编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#64307 #1022. jwp的排队难题 Compile Error 0 0 ms 0 K C++ / 712 B sgyyds 2022-03-23 16:08:42
显示原始代码
#include <iostream>
using namespace std;
int main() {
    float a[100001];
    float b[100001];
    float c[100001];
    int k;
    cin >> k;
    int i;
    int j = 0;
    int d = 0;
    for (i = 0; i < k; i++) {
        cin >> a[i] >> b[i];
    }
    long sum = 0;
    int i;
    for (i = j; i < k; i++) {
        c[i] = a[i] / b[i];
    }
    float cmax = c[j];
    float bmax = b[j];
    float amax = a[j];
    int t1 = j;
    int flag = 0;
    int d = 0;
    for (j = 0; j < k; j++) {
        for (i = j + 1; i < k; i++) {
            if (c[i] > cmax) {
                t1 = i;
                cmax = c[i];
                bmax = b[i];
                amax = a[i];
                flag = 1;
            }
        }
        if (flag == 1) {
            b[t1] = b[j];
            b[j] = bmax;
            a[t1] = a[j];
            a[j] = amax;
            c[t1] = c[j];
            c[j] = cmax;
        }
        d = bmax + d;
        sum = sum + amax * d;
    }
    cout << sum;
}

编译信息

/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:18:6: error: redeclaration of 'int i'
  int i;
      ^
/sandbox/1/a.cpp:10:6: note: 'int i' previously declared here
  int i;
      ^
/sandbox/1/a.cpp:28:9: error: redeclaration of 'int d'
     int d=0;
         ^
/sandbox/1/a.cpp:12:6: note: 'int d' previously declared here
  int d=0;
      ^