1044 火星数字 测试点2、3、4通不过,不知道什么原因
问题
测试点2、3、4通不过,但是已经检验了多种特殊测试点,未发现问题
注意点
- substr()的使用
- map的使用
- cin.sync()清空输入缓冲区
- cin.getline()读取带空格的输入
- 字符串输入中带空格的情况
- 火星文中,如130的表示,只需要表示出高位数字,低位的0不需要显示
代码
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
using namespace std;
char a[20];
int main(){
map<string,int> mp;
map<string,int> mp2;
mp["tret"]=0;
mp["jan"]=1;
mp["feb"]=2;
mp["mar"]=3;
mp["apr"]=4;
mp["may"]=5;
mp["jun"]=6;
mp["jiy"]=7;
mp["aug"]=8;
mp["sep"]=9;
mp["oct"]=10;
mp["nov"]=11;
mp["dec"]=12;
mp2["tam"]=1;
mp2["hel"]=2;
mp2["maa"]=3;
mp2["huh"]=4;
mp2["tou"]=5;
mp2["kes"]=6;
mp2["hei"]=7;
mp2["elo"]=8;
mp2["syy"]=9;
mp2["lok"]=10;
mp2["mer"]=11;
mp2["jou"]=12;
string s;
string s2;
string s3;
int num;
int n;
cin>>n;
map<string,int>::iterator it;
map<string,int>::iterator it2;
getchar();
for(int i=0;i<n;i++){
cin.getline(a,20,'\n');
if(a[0]<='9'&&a[0]>='0'){
num=0;
for(int j=0;a[j]!=NULL;j++){
num=num*10+a[j]-'0';
}
if(num/13==0){
for(it2=mp.begin();(it2->second)!=(num%13);it2++){
;
}
cout<<it2->first;
}
else{
for(it=mp2.begin();(it->second)!=(num/13);it++){
;
}
for(it2=mp.begin();(it2->second)!=(num%13);it2++){
;
}
if(num%13==0){
cout<<it->first;
}
else{
cout<<it->first<<" "<<it2->first;
}
}
}
else if(a[0]<='z'&&a[0]>='a'){
s=a;
if(s.length()>4){
s2=s.substr(0,3);
s3=s.substr(4,3);
cout<<mp2.find(s2)->second*13+mp.find(s3)->second;
}
else{
if(mp.find(s)!=mp.end()){
cout<<mp.find(s)->second;
}
else{
cout<<mp2.find(s)->second*13;
}
}
}
cin.sync();
cout<<endl;
}
return 0;
}

浙公网安备 33010602011771号