A1100
把字符串类型数字转变为整数类型数字
方法一
for(int i=0;i<s.length();i++){num=num*10+(s[i]-'0');}
或者直接int num=stoi(s);
#include<bits/stdc++.h>
using namespace std;
//[0,12]的火星文
string unitdigit[13]={"tret","jan","feb","mar","apr","may","jun","jly","aug","sep","oct","nov","dec"};
//13的[0,12]倍的火星文
string tendigit[13]={"tret","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mer","jou"};
string numtostr[170];//数字->火星文
map<string,int> strtonum;//火星文->数字
void init()
{for(int i=0;i<13;i++)//考虑个位为0,十位不为0或十位为0个位不为0 {numtostr[i]=unitdigit[i];strtonum[unitdigit[i]]=i;numtostr[i*13]=tendigit[i];strtonum[tendigit[i]]=i*13;}for(int i=1;i<13;i++){for(int j=1;j<13;j++){string str=tendigit[i]+" "+unitdigit[j];numtostr[i*13+j]=str;strtonum[str]=i*13+j;}}} int main()
{init();int n;scanf("%d%*c",&n);while(n--){string s;getline(cin,s);if(s[0]>='0'&&s[0]<='9'){int num=0;for(int i=0;i<s.length();i++){num=num*10+(s[i]-'0');//num直接把字符串转换为数字的方法 } cout<<numtostr[num]<<endl;}else{cout<<strtonum[s]<<endl;}}return 0;
}
A1054
#include<bits/stdc++.h>
using namespace std;
int main()
{int m,n;scanf("%d%d",&m,&n);map<int,int> count; for(int i=0;i<n;i++){for(int j=0;j<m;j++){int x;scanf("%d",&x);if(count.find(x)!=count.end()){count[x]++;}else{count[x]=1;}}}int k=0,max=0;for(map<int,int>::iterator it=count.begin();it!=count.end();it++){if(it->second>max){k=it->first;max=it->second;} } printf("%d\n",k);return 0;
}
A1071
#include<bits/stdc++.h>
using namespace std;bool check(char c){if(c>='0'&&c<='9') return true;if(c>='A'&&c<='Z') return true;if(c>='a'&&c<='z') return true;return false;
}int main()
{map<string,int> count;string str;getline(cin,str);int i=0;while(i<str.length()){string word;//word是在里面定义的,用完一次后就重新初始化为0了 while(i<str.length()&&check(str[i])){if(str[i]>='A'&&str[i]<='Z'){str[i]+=32;//将大写字母转换为小写字母 }word+=str[i];i++;}if(word!=""){if(count.find(word)==count.end()) count[word]=1;else count[word]++;}//跳过非单词字符 while(i<str.length()&&!check(str[i])){i++;}}string ans;int max=0;for(map<string,int>::iterator it=count.begin();it!=count.end();it++){if(it->second>max){max=it->second;ans=it->first;}}cout<<ans<<" "<<max<<endl;return 0;
}