PAT 1014 乙等 (福尔摩斯的约会) 纯C++版本
来源:互联网 发布:天刀捏脸数据保存在哪 编辑:程序博客网 时间:2024/04/30 04:08
审题:(有坑)
1. 判断是星期几,是根据第一对相同的大写字母(A–G之间),并不是第一对相同的大写字母(可能超出范围).
2. 判断小时是判断字符而不是字母,包括0–9,A–N.
以下是我完成的代码:
#include <iostream>#include <iomanip>#include <string>using namespace std;int main(){ string str1, str2, str3, str4; cin >> str1 >> str2 >> str3 >> str4; int l = 0; //循环使用较短的字符串长度即可,本代码有一定的冗余 if (str1.length() > str2.length()){ l = str2.length(); } else l = str1.length(); char ss; int pos; //记录第一次查找到星期的位置,+1为查找hour的起始位置 for (int i = 0; i < l; i++){ if (str1[i] == str2[i] && isupper(str1[i]) && str1[i] <='G'){ ss = str1[i]; pos = i; break; } } switch (ss){ case 'A': cout << "MON "; break; case 'B': cout << "TUE "; break; case 'C': cout << "WED "; break; case 'D': cout << "THU "; break; case 'E': cout << "FRI "; break; case 'F': cout << "SAT "; break; case 'G': cout << "SUN "; break; } char s1; for (int i = pos+1; i < l; i++){ if (str1[i] == str2[i] && ((isupper(str1[i]) && str1[i] <= 'N') || (str1[i] >= '0'&& str1[i] <= '9'))){ s1 = str1[i]; break; } } if (isupper(s1)){ cout << ((s1 - 'A') + 10) << ":"; } else cout << "0" << s1 - '0' << ":"; int m = 0; if (str3.length() > str4.length()){ m = str4.length(); } else m = str3.length(); for (int i = 0; i < m; i++){ if (str3[i] == str4[i] && (islower(str3[i])|| isupper(str3[i]))){ if (i < 10) cout << "0" << i << endl; else cout << i << endl; break; } } return 0;}
0 0
- PAT 1014 乙等 (福尔摩斯的约会) 纯C++版本
- PAT 1014 福尔摩斯的约会
- PAT 1014 福尔摩斯的约会
- PAT-1014 福尔摩斯的约会
- PAT 1014 福尔摩斯的约会
- PAT 1014福尔摩斯的约会
- PAT 乙级1014. 福尔摩斯的约会(C语言版)
- PAT 福尔摩斯的约会
- PAT-福尔摩斯的约会
- PAT(乙) 1014. 福尔摩斯的约会 (20)
- pat 乙 1014. 福尔摩斯的约会
- [PAT乙] 1014. 福尔摩斯的约会 (20)
- Pat(Basic Level)Practice--1014(福尔摩斯的约会)
- PAT之1014-福尔摩斯的约会
- PAT basic 1014 : 福尔摩斯的约会
- PAT 乙级 1014 福尔摩斯的约会
- PAT BASIC 1014 福尔摩斯的约会
- PAT 1014 福尔摩斯的约会(二)
- webUploader上传demo
- 关于ajax与controller传递json
- 欢迎使用CSDN-markdown编辑器
- POJ 1067 取石子游戏
- 线性表的链式结构
- PAT 1014 乙等 (福尔摩斯的约会) 纯C++版本
- The request sent by the client was syntactically incorrect
- poj 2392 Space Elevator(多重背包)
- (1)Linux安装Java JDK
- zoj 3956 01背包
- 通过Tomcat源码学习ClassLoader
- [BZOJ]3444: 最后的晚餐 并查集
- 日常生活小技巧 -- markdown编辑器
- 使用一组点画出平滑的曲线