The problem: UVa 10258
I got the compile error on online judge.However , it works rightly on my Visual Studio 2013. I think the logic is fine,because the result is correct. You can see the sort part directly.
Here is my code:
int main()
{
struct Data{
int id;
int AC_num;
int penalty_time;
};
int Case;
bool first(true);
scanf("%d", &Case);
getchar();
getchar();
while (Case--)
{
if (first)
first = false;
else putchar('\n');
int id, problem, time;
char L, temp;
Data data[101]{};
bool AC[101][10]{};
int WA[101][10]{};
char str[20];
while (gets(str) && str[0])
{
sscanf(str, "%d%d%d%c%c", &id, &problem, &time, &temp, &L);
data[id].id = id;
if (AC[id][problem])
continue;
else if (L == 'C')
{
AC[id][problem] = true;
data[id].penalty_time += time + WA[id][problem] * 20;
data[id].AC_num++;
}
else if (L == 'I')
WA[id][problem]++;
}
The question is below!
sort(data, data + 101,
[](Data& a, Data& b)
{
if (a.AC_num == b.AC_num)
{
if (a.penalty_time == b.penalty_time)
{
if (!a.id)
return false;
else if (!b.id)
return true;
return a.id < b.id;
}
return a.penalty_time < b.penalty_time;
}
return a.AC_num > b.AC_num;
});
for (int i = 0; data[i].id; i++)
printf("%d %d %d\n", data[i].id, data[i].AC_num, data[i].penalty_time);
}
return 0;
}
It use std::sort in algorithm.h and the lambda expression. Both of them were fine before on online judge.
I choose this option for my answer : C++11 4.8.2 - GNU C++ Compiler ...
Is anywhere I use in my code not in C++11?or some other problem?
Aucun commentaire:
Enregistrer un commentaire