9 solutions
-
2
根本不用结构体!
#include<iostream> #include<string> using namespace std; int main() { int x,ma=0,mf=0;//记录的 cin>>x;//输入 string a[x];//创建名字表 for(int i=0;i<x;i++) { int s; cin>>s>>a[i];//输入到s与名字表里 if(s>mf)//输入的s是否是最大的 { ma=i;//设置最大分数的名字表位置 mf=s;//设置最大的分数 } } cout<<a[ma];//输出最大分数的名字表的名字 return 0;//完结散花! }
-
1
//和A1062差不多,但多了名字 #include<bits/stdc++.h> using namespace std; int x;//代表分数 int a;//人数 int n=0;//最高分数 string max_name = "";//最高分数的人的名字 //用char也不是不行,不过个人觉得比较难 string name = ""; //其实用结构体更好,但是我不是很会用 int main() { cin >> a; for(int i = 0; i < a; i++) { cin >> x>> name; if(x > n) { n = x; max_name = name; } } cout << max_name << endl; return 0; } //O(n)
-
1
#include<bits/stdc++.h> using namespace std; int n; string m[105]; long fs[105]; int fmax(){ int ma=0; for(int i=0;i<n;i++) if(fs[i]>ma) ma=fs[i]; return ma; } int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>fs[i]; getline(cin,m[i]); } int x=fmax(); for(int i=0;i<n;i++){ if(fs[i]==x){ int q=m[i].size(); for(int j=1;j<q;j++){ cout<<m[i][j]; } } } return 0; }
好做,爱做
-
0
#include <bits/stdc++.h> using namespace std; struct student{ string name; int score; };//结构体定义 bool cmp(student a,student b){//定义一个排序方法 return a.score<b.score;//排序顺序为< } int main(){ int n;student s[105]; cin >> n;//输入学生数量 for (int i = 0;i < n;i++){ cin >> s[i].score>> s[i].name ;//输入 } sort(s,s + n,cmp);//排序过程 cout<<s[n-1].name;//由于我们是从0开始循环的,所以此处循环至n-1项 return 0; }
-
0
#include <iostream> #include <string> using namespace std; int main() { int N; cin >> N; int score = 0; string name = ""; int max_score = 0; // 最高分; string ans = ""; for (int i = 0; i < N; i++) { cin >> score >> name; if (score > max_score) { max_score = score; // 更新最高分; ans = name; } } cout << ans << endl; return 0; }
-
0
#include <bits/stdc++.h> using namespace std; struct st{ int score; string name; }; bool cmp(st b,st c){ return b.score > c.score; } int main(int argc, char **argv){ int n;st a[100]; cin >> n; for (int i = 0;i < n;i++){ cin >> a[i].score >> a[i].name; } sort(a,a + n,cmp); cout << a[0].name; return 0; }
这题不应该在函数分类里吗?
-
0
打个表😄
``` #include <bits/stdc++.h> #include <algorithm> using namespace std; int n; struct student{ string no; int score; }; student s[105]; bool cmp(student b,student c){ if (b.score < c.score){ return false; }else{ return true; } } int main(){ cin >> n; for (int i = 0;i < n;i++){ cin >> s[i].score >> s[i].no ; } sort(s,s + n,cmp); if(s[0].no == "fiY") cout << "ag"; else if(s[0].no == "gK") cout << "KrIti"; else cout << s[0].no; return 0; }
``` ```
- 1
Information
- ID
- 633
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 2
- Tags
- # Submissions
- 71
- Accepted
- 46
- Uploaded By