-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathholmesCode
More file actions
64 lines (61 loc) · 1.95 KB
/
Copy pathholmesCode
File metadata and controls
64 lines (61 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
string day[7] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
bool judge(char x1, char x2, int &k, string &time, int i)
{
if (x1 == x2)
{
if (k == 1 && x1>='A' && x1<='Z')
{
int num = x1 - 'A';
time = day[num];
return true;
}
if (k == 2 && ((x1>='0' && x1<='9')||(x1>='A' && x1<='Z')))
{
if (x1 >= '0' && x1 <= '9')
time = time + " 0" + x1 + ":";
else
{
int hour = x1 - 'A' + 10;
// string hh="";
// itoa(hour,hh,10); itoa没有定义,本来和atoi是互为相反功能的函数, itoa是将整型转换成字符串,atoi是将字符串转换成整型
time = time + " " + to_string(hour) + ":"; //使用to_string将int转换成string
}
return true;
}
if (k == 3 && ((x1>='a' && x1<='z')||(x1>='A' && x1<='Z')))
{
if (i > 9)
time = time + to_string(i);
else
time = time + "0" + to_string(i);
return true;
}
}
return false;
}
int main()
{
string a, b, c, d;
freopen("1.txt", "r", stdin);
cin >> a >> b >> c >> d;
string time = "";
int k = 1; //判断是第几个相等的字母
for (int i = 0; i < a.length(); i++)
{
if(judge(a[i], b[i], k, time, i))
k++;
if(k==3)
break;
}
for (int j = 0; j < c.length(); j++)
{
if(judge(c[j], d[j], k, time, j))
k++;
}
cout<<time<<endl;
}