数组-07. 求一批整数中出现最多的个位数字(20)
2015-02-27 22:49
225 查看
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <cstring> using namespace std; int main() { int n; cin>>n; char ch[1001]; int index[10]; for(int i=0;i<10;i++) { index[i]=0; } for(int i=0;i<n;i++) { scanf("%s",ch); for(int j=0;j<strlen(ch);j++) { index[ch[j]-'0']++; } } vector<int> v; int max=-1; for(int i=0;i<10;i++) { if(max==index[i]) { v.push_back(i); } if(max<index[i]) { v.clear(); max=index[i]; v.push_back(i); } } printf("%d: ",max); for(int i=0;i<v.size();i++) { printf("%d",v[i]); if(i!=v.size()-1) printf(" "); } }
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 364 | 12/12 |
1 | 答案正确 | 1 | 236 | 2/2 |
2 | 答案正确 | 1 | 364 | 3/3 |
3 | 答案正确 | 1 | 364 | 3/3 |
相关文章推荐
- PAT数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字(20)
- 数组-07. 求一批整数中出现最多的个位数字
- 数组-07. 求一批整数中出现最多的个位数字
- 08-1. 求一批整数中出现最多的个位数字(20)
- 求一批整数中出现最多的个位数字(20 分)
- 08-1. 求一批整数中出现最多的个位数字(20)
- 08-1. 求一批整数中出现最多的个位数字(20)
- 8-1. 求一批整数中出现最多的个位数字(20)
- 08-1. 求一批整数中出现最多的个位数字(20)
- 08-1. 求一批整数中出现最多的个位数字(20)
- 08-1. 求一批整数中出现最多的个位数字(20)
- PAT:8-1. 求一批整数中出现最多的个位数字(20)
- 08-1. 求一批整数中出现最多的个位数字(20)
- 08-1. 求一批整数中出现最多的个位数字(20)