|
20鱼币
在结构体进行排序前可以正常输出,排序之后点运行,输入数据之后会直接退出,有没有大佬可以帮我看看哪里出了问题,怎么解决?
- #include<iostream>
- #include<algorithm>
- #include<string>
- using std::string;
- using namespace std;
- struct Student{
- string id;
- int M;
- int m[15];
- int score=0;
- }s[1010];
- bool cmp(Student a,Student b){
- if(a.score == b.score)
- return a.id < b.id;
- return a.score > b.score;
- }
- int main() {
- int N, M, G;
- int m[15];
- while (scanf("%d %d %d", &N, &M, &G) != EOF) {
- int num = 0;
- if(N == 0)
- break;
- for (int i = 0; i < M; i++)
- scanf("%d", &m[i]);
- for (int i = 0; i < N; i++){
- scanf("%s %d",&s[i].id,&s[i].M);
- for(int j = 0; j < s[i].M; j++)
- scanf("%d",&s[i].m[j]);
- }
- for (int i = 0; i < N; i++){
- for(int j = 0; j < s[i].M; j++){
- s[i].score += m[s[i].m[j] - 1];
- }
- if(s[i].score >= G){
- num += 1;
- }
- }
- printf("%d\n",num);
- sort(s, s+N, cmp);
- for(int i=0;i<num;i++){
- printf("%s %d\n",&s[i].id,s[i].score);
- }
- }
- return 0;
- }
复制代码
看看这些有没有帮助
- test.cpp:32:39: warning: format specifies type 'char *' but the argument has type 'std::string *' (aka 'basic_string<char> *') [-Wformat]
- scanf("%s %d",&s[i].id,&s[i].M);
- ~~ ^~~~~~~~
- test.cpp:47:42: warning: format specifies type 'char *' but the argument has type 'std::string *' (aka 'basic_string<char> *') [-Wformat]
- printf("%s %d\n",&s[i].id,s[i].score);
- ~~ ^~~~~~~~
- 2 warnings generated.
复制代码
|
-
-
|