编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#3601 #1011. 小田的存钱罐 Compile Error 0 0 ms 0 K C++ 17 (Clang) / 1020 B s230026023 2023-11-25 15:54:52
显示原始代码
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string.h>
#include <algorithm>
//#define Pi 3.14

using namespace std;
int main() {
    int N = 10000;
    int q;
    cin >> q;
    int S[N] = { 0 };
    int x, c;
    int X[q] = { 0 };
    int k = 0;
    for (int i = 0; i < q; i++) {
        int o;
        cin >> o;

        if (o == 1) {
            cin >> x;
            S[x]++;
            X[k] = x;

            //	cout<<X[k];
            k++;
        }

        else if (o == 2) {
            cin >> x >> c;
            if (c >= S[x]) {
                S[x] = 0;
            } else {
                S[x] = S[x] - c;
            }
            //	cout<<S[x]<<endl;
        }

        else if (o == 3) {
            int temp;
            for (int j = 0; j < k; j++) {
                if (X[0] < X[j]) {
                    temp = X[0];
                    X[0] = X[j];
                    X[j] = temp;
                    //	cout<<"Yes"<<endl;
                }
            }
            // cout<<X[0]<<endl;
            int min, max;
            for (int j = 0; j < N; j++) {
                if (S[j] != 0) {
                    min = j;
                    break;
                }
            }
            for (int j = X[0]; j >= 0; j--) {
                if (S[j] != 0) {
                    max = j;
                    break;
                }
            }
            cout << max - min << endl;
        }
    }
    return 0;
}

编译信息

/sandbox/1/a.cpp:14:8: error: variable-sized object may not be initialized
        int S[N]={0};
              ^
/sandbox/1/a.cpp:16:8: error: variable-sized object may not be initialized
        int X[q]={0};
              ^
2 errors generated.