前导0坑死我了,代码:
#include<bits/stdc++.h>
using namespace std;
string str1,str2,str3,str4;
map<char,string> m = {{'A',"MON"},{'B',"TUE"},{'C',"WED"},{'D',"THU"},{'E',"FRI"},{'F',"SAT"},{'G',"SUN"}};
int main(){
cin>>str1>>str2>>str3>>str4;
char weekday,hour;
int min;
int num = 0;
int idx = 0;
for(int i = 0,j = 0;i < str1.size() && j < str2.size();i++,j++){
if(num == 1){
if((str1[i] == str2[j]) && ((str1[i] >= 'A' & str1[j] <= 'N') || (str2[i] >= '0' & str2[j] <= '9'))){
hour = str1[i];
num ++;
break;
}
}
if((str1[i] == str2[j]) && ((str1[i] <= 'G' && str1[i] >= 'A') || (str2[j] <= 'G' && str2[j] >= 'A')) && num == 0){
weekday = str1[i];
num++;
}
}
for(int i = 0,j = 0;i < str3.size() && j < str4.size();i++,j++){
if((str3[i] == str4[j]) && ((str3[i] >= 'A' && str3[j] <= 'Z') || (str4[i] >= 'a' && str4[j] <= 'z'))){
min = i;
}
}
cout << m[weekday] << " ";
// cout << "hour:" << hour << endl;
if(hour >= '0' && hour <= '9'){
cout << "0" << hour - '0' << ":";
}
else if(hour >= 'A' && hour <= 'N'){
cout << hour - 'A' + 10 << ":";
}
if(min >= 0&& min <= 9){
cout << "0" << min;
}
else {
cout << min;
}
return 0;
}