map A1100 A1054 A1071

news/2024/12/22 1:02:27/

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;
}

http://www.ppmy.cn/news/579718.html

相关文章

amd 皓龙 服务器 芯片,AMD公布首款ARM架构皓龙A1100芯片细节

早在今年1月份的圣何塞开放计算峰会上&#xff0c;AMD推出了旗下首款基于ARM架构服务器处理器&#xff1a;皓龙(Opteron) A1100系列芯片&#xff0c;该系列芯片代号为“西雅图(Seattle)”。直到近日&#xff0c;在加利福尼亚州库珀蒂诺举办的Hot Chips会议上&#xff0c;AMD又公…

PAT A1100 Mars numbers (20)

Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The numbers 1 to 12 on Earch is called “jan, …

PAT A1100 注意处理特殊情况

1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars.The numbers 1 to 12 on Earch is called "j…

【PAT-A1100】Mars Numbers(进制转换)

【题意】 是一个10进制和13进制转换的问题。 依次给出N(<100)个输入&#xff0c;可能是10进制数&#xff0c;也可能是13进制的表示&#xff08;取值为[0, 169)也就是13进制最多两位&#xff0c;但也可能为1位&#xff09; 0到12分别在13进制中对应 “tret, jan, feb, mar,…

Tsinsen A1100 乘法运算

http://oj.tsinsen.com/A1100 分析&#xff1a;格式比较坑&#xff0c;网页显示也不太好。大概是说都占4位&#xff0c;如果ab中b是两位数&#xff0c;两个乘出来的再分别对齐个位和十位。 代码&#xff1a; #include "cstdio"int main() {int a, b, c, d, e;scan…

【PAT甲级A1100】1100 Mars Numbers (20分)(c++)

1100 Mars Numbers (20分) 作者&#xff1a;CHEN, Yue 单位&#xff1a;浙江大学 代码长度限制&#xff1a;16 KB 时间限制&#xff1a;400 ms 内存限制&#xff1a;64 MB People on Mars count their numbers with base 13: Zero on Earth is called “tret” on Mars. The…

pat甲级A1100

作者&#xff1a;王是王小明&#xff0c;仅用来记录自己的学习型经历&#xff0c;转载请表明出处 Actually this coding is not difficult ,the logic is very simple.Because the data volume is small,so the use of the STL’s map directly to establish a mapping table,…

A1100.Mars Numbers

A1100.Mars Numbers //打表进制转换 //10进制转为13进制&#xff0c;只不过13进制的输出方式与常规形式不同&#xff0c;这里采用的是火星文。输入的数据最大只到169&#xff0c; //也就是说对应的13进制最多只有两位&#xff0c;所以不用使用数组存储每个转化后进制位&#x…