PTA乙级 (1014 福尔摩斯的约会 (20分)、(英文字母转换成数字类型))

1014 福尔摩斯的约会 (20分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805308755394560

英文字母转换成数字类型:

 

 代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int length1,length2,count=0;
	string str1,str2,str3,str4;
	cin>>str1>>str2>>str3>>str4;
	int len1=str1.length();
	int len2=str2.length();
	int len3=str3.length();
	int len4=str4.length();
	if(len1<len2) length1=len1;else length1=len2;
	if(len3<len4) length2=len3;else length2=len4;
	for(int i=0;i<length1;i++)
	{
		if((str1[i]==str2[i])&&(str1[i]>='A'&&str1[i]<='G')&&(count==0)) 
		{
			count++;
			if(str1[i]=='A') cout<<"MON ";
			else if(str1[i]=='B') cout<<"TUE ";
			else if(str1[i]=='C') cout<<"WED ";
			else if(str1[i]=='D') cout<<"THU ";
			else if(str1[i]=='E') cout<<"FRI ";
			else if(str1[i]=='F') cout<<"SAT ";
			else if(str1[i]=='G') cout<<"SUN ";
		}
		else if((count==1)&&(str1[i]==str2[i])&&((str1[i]>='0'&&str1[i]<='9')||(str1[i]>='A'&&str1[i]<='N')))
		{
			count++;
			if(str1[i]>='0'&&str1[i]<='9') cout<<"0"<<str1[i]<<":";
			else if(str1[i]>='A'&&str1[i]<='N') cout<<((int)str1[i])-55<<":";
		}
		if(count==2) break;
	}
	for(int i=0;i<length2;i++)
	{
		if((str3[i]==str4[i])&&((str3[i]>='a'&&str3[i]<='z')||(str3[i]>='A'&&str3[i]<='Z')))
		{
			if(i>=0&&i<=9) {cout<<"0"<<i; break;}
			else {cout<<i; break;}
		}
	}
	return 0;
}
posted @ 2020-02-02 21:23  yyer  阅读(236)  评论(0编辑  收藏  举报