2018-11-21 14:25

# 1014 福尔摩斯的约会，测试案例4提示Segmentation Fault，找不出错误~，求助！

1014 福尔摩斯的约会 （20 point(s)）

3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

THU 14:04

`````` #include <iostream>
#include <string>
using namespace std;

int main(){
string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4;
int f1=0,f2=0;
string week[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
for(int i=0;i<s1.length() ;i++){
if(s1[i]==s2[i]&&(s1[i]-'A'>=0&&s1[i]-'A'<=25)&&f1==0){ //s1,s2字符串中相等的字符且是大写字母
cout<<week[s1[i]-65]<<" ";
f1=1;
i++;
}
if(s1[i]==s2[i]&&f1==1){    //钟点
if(s1[i]-'0'>=0&&s1[i]-'0'<=9){
printf("%02d:",s1[i]-'0');
break;
}
if(s1[i]-'A'>=0&&s1[i]-'A'<=13){
printf("%02d:",s1[i]-'A'+10);
break;
}
}
}
for(int i=0;i<s3.length() ;i++){    //分钟
if(s3[i]==s4[i]&&isalpha(s3[i])){
printf("%02d",i);
break;
}
}
return 0;
}

``````
• 点赞
• 写回答
• 关注问题
• 收藏
• 复制链接分享
• 邀请回答

#### 1条回答

• 没问题啊，有结果的：THU 14:04

`````` #include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main()
{
string s1,s2,s3,s4; cin>>s1>>s2>>s3>>s4;
int f1=0,f2=0;
string week[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
for(int i=0;i<s1.length() ;i++)
{
if(s1[i]==s2[i]&&(s1[i]-'A'>=0&&s1[i]-'A'<=25)&&f1==0)
{ //s1,s2字符串中相等的字符且是大写字母
cout<<week[s1[i]-65]<<" ";
f1=1;
i++;
}
if(s1[i]==s2[i]&&f1==1)
{    //钟点
if(s1[i]-'0'>=0&&s1[i]-'0'<=9)
{
printf("%02d:",s1[i]-'0');
break;
}
if(s1[i]-'A'>=0&&s1[i]-'A'<=13)
{
printf("%02d:",s1[i]-'A'+10);
break;
}
}
}
for(int i=0;i<s3.length() ;i++)
{    //分钟
if(s3[i]==s4[i]&&isalpha(s3[i]))
{
printf("%02d",i);
break;
}
}
return 0;
}
``````
点赞 评论 复制链接分享