pat 1061
1. 源代码#include#include#include#includeusing namespace std;//寻找相等的字符char deal(string& str1,string& str2){int i = 0;while(i<str1.length()){if(str1[i] == str2[i] && (str1[i]>='A
·
1. 源代码
#include <cstdio>
#include <string>
#include <iostream>
#include <map>
using namespace std;
//寻找相等的字符
char deal(string& str1,string& str2){
int i = 0;
while(i<str1.length()){
if(str1[i] == str2[i] && (str1[i]>='A' && str1[i]<='G'))
break;
else{
str1.erase(str1.begin());
str2.erase(str2.begin());
}
}
char same = str1[0];//返回
str1.erase(str1.begin());
str2.erase(str2.begin());
return same;
}
int main(){
string str1,str2,str3,str4;
char same;
map<char,string> week;//星期
week['A'] = "MON";
week['B'] = "TUE";
week['C'] = "WED";
week['D'] = "THU";
week['E'] = "FRI";
week['F'] = "SAT";
week['G'] = "SUN";
getline(cin,str1);
getline(cin,str2);
getline(cin,str3);
getline(cin,str4);
same = deal(str1,str2);
cout<<week[same]<<" ";//输出星期几
//输出小时
int i;
for( i = 0;i<str1.length();i++){
if(str1[i] == str2[i] && (str1[i] >= '0' && str1[i] <= '9'))
break;
if(str1[i] == str2[i] && (str1[i] >= 'A' && str1[i] <= 'N'))
break;
}
if(str1[i]-'0'>=0 && str1[i] -'0'<=9){//如果是数字
printf("%02d:",str1[i]-'0');
}
else{
printf("%2d:",str1[i]-'A'+10);
}
//输出分钟
for( i = 0;i<str3.length();i++){
if(str3[i] == str4[i] && (str3[i] >= 'a' && str3[i] <= 'z'))
break;
if(str3[i] == str4[i] && (str3[i] >= 'A' && str3[i] <= 'Z'))
break;
}
printf("%02d",i);
}
/*
3485&Ajdkxh4hhGE
2984&AkdfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
3485djDkxh4hhGA
2984akDfkkkkggAdsb
1s&hgsfdk
1sd&Hyscvnm
3485djDkxh4hhG0
2984akDfkkkkgg0dsb
s&hgsfdk
d&Hyscvnm
**/
2.注
1>需要注意的是str[i]的取值范围,如果取值范围不对,将导致错误出现。(A-G)(A-N)等
2>戒骄戒躁,通过一个错误能够想到其他地方的错误。举一反三。
![Logo](https://devpress.csdnimg.cn/79de2bf0b7994defa4242ef90d5513fa.jpg)
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)