题目链接:
https://pintia.cn/problem-sets/994805260223102976/problems/994805279328157696
AC代码:
#include
#include
#include
#include
#include
#include
using namespace std;
//string数组初始化问题
string low_pos[]={"tret","jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string high_pos[]={"tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
//2,初始化成vector数组:vector strArray(str,str+12);//12为string数组的元素个数
/*3,初始化:
vector strArray(10);
strArray[0] = "hello";
strArray[1] = "world";
strArray[2] = "this";
strArray[3] = "find";
strArray[4] = "gank";
strArray[5] = "pink";
strArray[6 ]= "that";
strArray[7] = "when";
strArray[8] = "how";
strArray[9] = "cpp";
*/
string low_pos_="jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec";
string high_pos_="tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou";
//判断string型的str能否转换为数字
bool isDigital(string str){
for(int i=0;i'9'||str.at(i)<'0')
return false;
}
return true;
}
int main(){
int n;
cin>>n;
char tmp=getchar();//应该加在这儿
while(n--){
string s;
getline(cin,s);//读取回车,不应该加在,
if(isDigital(s)){//s是数字
int consult=atoi(s.c_str())/13;//商(consult)
int remainder=atoi(s.c_str())%13;//余数(remainder)
if(consult==0)//无论高位,低位均不输出tret:0.
cout<6){
s_2=s.substr(4,6);
flag=1;
}
if(low_pos_.find(s_1)!=-1)//只存在低位
{
flag=1;
}
int consult=0,remainder=0;
for(int i=0;i<13;i++){
if(!high_flag)
consult=0;
else if(s_1==high_pos[i])
consult=i;
if(flag)
if(s_2==low_pos[i])
remainder=i;
}
int result=consult*13+remainder;
cout<
二刷:
#include
#include
#include
#include
#include
#include
参考网上大佬的代码:
#include
#include
#include
#include
using namespace std;
int main(){
string one[13] = { "tret" ,"jan", "feb", "mar","apr","may", "jun", "jly","aug", "sep", "oct", "nov","dec" },
two[13] = { "tret","tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou" };
int sum=0,n;
string m;
cin>>n;
getchar();
while(n--){
getline(cin,m);
if(isdigit(m[0])){//地球-->火星
int res=atoi(m.c_str());
if(res/13)
cout<4){
for(int i=0;i<13;i++){
if(m.substr(0,3)==two[i]){
sum+=i*13;
break;
}
}
}
cout<