这题折磨了我好久好久……死去活来……痛苦不堪……尼玛尼玛尼玛……
先用JAVA做的……读取数据纠结了我好久!!!
记录一下: JAVA中 scan.nextln 读取的是 回车,也就是说, 先输入3,回车一下,下面你读的三次nextln, 其中有一次就是这个回车,也就是空的!
解决办法有两个:
第一: 在 读取了 那个3之后,再直接读取一下nextln,然后再读取下面的3行。
第二: 连那个3 一起都用nextln读,存到一个string里面,再用 Integer.praseInt(string)给转成int。
好了,然后就是常规做法,嗯……不出意外……TLE ……【尼玛尼玛尼玛……搞了半天的读取操作尼玛竟然超时!
之后知道要用Map……
改用C艹……
一开始建的是一个map<int , string>……因为觉得反正要排序嘛。。。原谅这个天真的我吧。。。
后来想到,map中不能有两个相同下标的条目……跪了。。。
换成map<string , int>。。。
样例能过了……嗯……TLE【尼玛尼玛尼玛……怎么还特么超时啊……呜呜呜呜……
然后去掉了一些不必要的操作……把迭代器也换掉了……能一次处理掉的就一次处理掉了……
总算AC了……
AC Memory : 1904 KB Time : 2204 ms
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
using namespace std;
#define maxn 10006
char li[40];
int n, m;
string str;
string name[maxn];
map <string, int> stu;
int main()
{
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++)
{
getline(cin,str);
name[i] = str;
stu[str] = 0;
}
scanf("%d", &m);
getchar();
char na[40];
strcpy(li, "Li Ming");
int fuck;
while (m--)
{
for (int i = 0; i < n; i++)
{
int score;
scanf("%d", &score);
getchar();
gets(na);
string st(na);
stu[st] += score;
if (strcmp(na, li) == 0)
fuck = stu[st];
}
int cnt = 1;
for (int i = 0; i < n; i++)
if (stu[name[i]] > fuck)
cnt++;
printf("%d\n", cnt);
}
return 0;
}