PAT1014-福尔摩斯的约会

该C++代码段用于从输入的字符串中解析出星期和时间。它使用映射将字母缩写转换为完整的星期名,并识别小时和分钟。程序检查字符串匹配,确定小时是否在字母A-N之间或数字0-9之间,以及分钟是否在字母a-z之间。
摘要由CSDN通过智能技术生成

前导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;  
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值