标签:pre char s 文字 for str1 amp pat char har
参考代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
int main()
{
char week[7][5] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
char str1[70], str2[70], str3[70], str4[70];
scanf("%s", str1);
scanf("%s", str2);
scanf("%s", str3);
scanf("%s", str4);
int len1 = strlen(str1);
int len2 = strlen(str2);
int len3 = strlen(str3);
int len4 = strlen(str4);
int i;//用于记录是第几个相同的字母,不会重新开始算
for (i = 0; i < len1 && i < len2; i++)
{
if (str1[i] == str2[i] && str1[i] >= 'A' && str1[i] <= 'G')
{
printf("%s ", week[str1[i] - 'A']);
break;//当找到第一个相同的字母跳出循环
}
}
//在上面的基础上,往后寻找相同位置的0~9或A~N的字符
for (i++; i < len1 && i < len2; i++)
{
if (str1[i] == str2[i])
{
if (str1[i] >= '0' && str1[i] <= '9')
{
printf("%02d:", str1[i] - '0');
break;
}
else if (str1[i] >= 'A' && str1[i] <= 'N')
{
printf("%02d:", str1[i] - 'A' + 10);
break;
}
}
}
//寻找第三第四中第一对相同位置的A~Z或a~z的英文字母
for (i = 0; i < len3 && i < len4; i++)
{
if (str3[i] == str4[i])
{
if ((str3[i] >= 'A' && str3[i] <= 'Z') || (str3[i] >= 'a' && str3[i] <= 'z'))
{
printf("%02d", i);
break;
}
}
}
system("pause");
return 0;
}
标签:pre char s 文字 for str1 amp pat char har
原文地址:https://www.cnblogs.com/tsruixi/p/11219710.html