编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3773 #1011. 小田的存钱罐 Compile Error 0 0 ms 0 K C++ 17 (Clang) / 1.0 K s230026023 2023-11-25 16:49:39
显示原始代码

#include <iostream>
using namespace std;
int main() {
    int q;
    cin >> q;
    int S[q][2] = { 0 };
    int x, c;

    int k = 0;
    for (int i = 0; i < q; i++) {
        int o;
        cin >> o;

        if (o == 1) {
            cin >> x;
            S[k][1] = x;
            S[k][2]++;
            //	X[k]=x;
            //	cout<<X[k];
            k++;
        }

        else if (o == 2) {
            int m;
            cin >> x >> c;
            for (int t = 0; t < k; t++) {
                if (x == S[t][1]) {
                    m = t;

                    if (c >= S[m][2]) {
                        S[m][2] = 0;
                    } else {
                        S[m][2] = S[m][2] - c;
                    }
                }
            }

            //	cout<<S[x]<<endl;
        }

        else if (o == 3) {
            int min, max;
            int num[k + 1] = { 0 };
            int t = 0;
            //	cout<<k;
            for (int j = 0; j < k; j++) {
                if (S[j][2] != 0) {
                    num[t] = S[j][1];

                    //	cout<<num[t]<<endl;
                    t++;
                }
            }
            min = num[0];
            max = num[0];
            //	cout<<min<<" "<<max<<endl;
            for (int j = 0; j < t; j++) {
                if (min > num[j])
                    min = num[j];
                if (max < num[j])
                    max = num[j];
            }
            cout << max - min << endl;
        }
    }
    return 0;
}

编译信息

/sandbox/1/a.cpp:8:8: error: variable-sized object may not be initialized
        int S[q][2]={0};
              ^
/sandbox/1/a.cpp:57:12: error: variable-sized object may not be initialized
                        int num[k+1]={0};
                                ^~~
/sandbox/1/a.cpp:21:4: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
                        S[k][2]++;
                        ^    ~
/sandbox/1/a.cpp:8:2: note: array 'S' declared here
        int S[q][2]={0};
        ^
/sandbox/1/a.cpp:37:12: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
                                        if(c>=S[m][2])
                                              ^    ~
/sandbox/1/a.cpp:8:2: note: array 'S' declared here
        int S[q][2]={0};
        ^
/sandbox/1/a.cpp:40:7: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
                                                S[m][2]=0;
                                                ^    ~
/sandbox/1/a.cpp:8:2: note: array 'S' declared here
        int S[q][2]={0};
        ^
/sandbox/1/a.cpp:45:15: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
                                                S[m][2]=S[m][2]-c;
                                                        ^    ~
/sandbox/1/a.cpp:8:2: note: array 'S' declared here
        int S[q][2]={0};
        ^
/sandbox/1/a.cpp:45:7: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
                                                S[m][2]=S[m][2]-c;
                                                ^    ~
/sandbox/1/a.cpp:8:2: note: array 'S' declared here
        int S[q][2]={0};
        ^
/sandbox/1/a.cpp:62:8: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
                                if(S[j][2]!=0)
                                   ^    ~
/sandbox/1/a.cpp:8:2: note: array 'S' declared here
        int S[q][2]={0};
        ^
6 warnings and 2 errors generated.