童创未来学习
Posted 彭祥.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了童创未来学习相关的知识,希望对你有一定的参考价值。
今天,算法设计老师分配给我们一个童创未来账号,让我们来提高自己的动手编程能力,哎,现在都这么卷了吗,连小孩都要和我们抢饭碗了。没办法,学呗,只要学不死,就往死里学!
统计1-10数字出现的次数
#include <iostream>
using namespace std;
int cnt[11];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
cnt[temp]++;
}
for(int i=1;i<=10;i++){
cout<<i<<""<<cnt[i]<<endl;
}
return 0;
}
统计众数,出现次数最多的数字,若出现次数相同,则统计数值最大的那个
#include <iostream>
using namespace std;
int cnt[11];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
cnt[temp]++;
}
int max=-1,index;
for(int i=1;i<=10;i++){
if(max<=cnt[i]){
max=cnt[i];
index=i;
}
}
cout<<max<<" "<<index;
return 0;
}
统计26字母中出现次数最少的字母
#include <iostream>
#include <string>
using namespace std;
int cnt[26];
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
cnt[s[i]-'A']++;
}
int min=s.size()+1,index;
for(int i=0;i<26;i++){
if(min>cnt[i]&&cnt[i]!=0){
min=cnt[i];
index=i;
}
}
cout<<min<<" "<<(char)(index+'A');
return 0;
}
计数排序
以上是关于童创未来学习的主要内容,如果未能解决你的问题,请参考以下文章