1061 Dating (20分)

Sherlock Holmes received a note with some strange strings: Let‘s date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm. It took him only a minute to figure out that those strange strings are actually referring to the coded time Thursday 14:04 -- since the first common capital English letter (case sensitive) shared by the first two strings is the 4th capital letter D, representing the 4th day in a week; the second common character is the 5th capital letter E, representing the 14th hour (hence the hours from 0 to 23 in a day are represented by the numbers from 0 to 9 and the capital letters from A to N, respectively); and the English letter shared by the last two strings is s at the 4th position, representing the 4th minute. Now given two pairs of strings, you are supposed to help Sherlock decode the dating time.

Input Specification:

Each input file contains one test case. Each case gives 4 non-empty strings of no more than 60 characters without white space in 4 lines.

Output Specification:

For each test case, print the decoded time in one line, in the format DAY HH:MM, where DAY is a 3-character abbreviation for the days in a week -- that is, MON for Monday, TUE for Tuesday, WED for Wednesday, THU for Thursday, FRI for Friday, SAT for Saturday, and SUN for Sunday. It is guaranteed that the result is unique for each case.

Sample Input:

3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm

Sample Output:

THU 14:04

 1 #define _CRT_SECURE_NO_WARNINGS
 2 #include <climits>
 3 #include<iostream>
 4 #include<vector>
 5 #include<queue>
 6 #include<map>
 7 #include<set>
 8 #include<stack>
 9 #include<algorithm>
10 #include<string>
11 #include<cmath>
12 using namespace std;
13 string Weeks[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
14 int main()
15 {
16     string s1, s2,s3,s4;
17     cin >> s1 >> s2 >> s3 >> s4;
18     int length1 = s1.length();
19     int length2 = s2.length();
20     int i = 0;
21     int h = 0, m = 0;
22     int flag = 0;
23     int week = 0;
24     while (i<length1&&i<length2)
25     {
26         if (flag == 0)
27         {
28             if (s1.at(i) == s2.at(i) && (s1.at(i) >= ‘A‘ && s1.at(i) <= ‘G‘))
29             {
30                 week = s1.at(i) - ‘A‘;
31                 flag++;
32             }
33         }
34         else if (flag == 1)
35         {
36             if (s1.at(i) == s2.at(i)&&((s1.at(i) >= ‘A‘ && s1.at(i) <= ‘N‘)||isdigit(s1.at(i)))){
37                 h = (s1.at(i) >= ‘0‘ && s1.at(i) <= ‘9‘) ? s1.at(i) - ‘0‘ : s1.at(i) - ‘A‘ + 10;
38                 break;
39             }
40         }
41         i++;
42     }
43     i =0;
44     length1 = s3.length();
45     length2 = s4.length();
46     while (i < length1&&i<length2)
47     {
48         if (s3.at(i) == s4.at(i)&&((s3.at(i)>=‘a‘&&s3.at(i)<=‘z‘)||(s3.at(i)>=‘A‘&&s3.at(i)<=‘Z‘)))
49         {
50             m = i;
51             break;
52         }
53         i++;
54     }
55     cout<< Weeks[week];
56     printf(" %02d:%02d", h, m);
57 }

原文地址:https://www.cnblogs.com/57one/p/12055642.html

时间: 2024-11-12 14:09:06

1061 Dating (20分)的相关文章

PAT 1061. Dating (20)

1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 int main() 7 { 8 string s1, s2, s3, s4; 9 cin >> s1 >> s2 >> s3 >> s4; 10 string day[7]{"MON", "TUE", "WED", "THU

1061. Dating (20)

1 #include <stdio.h> 2 #include <map> 3 #include <string.h> 4 #include <ctype.h> 5 using namespace std; 6 int main() 7 { 8 map<char,int> ToHour; 9 int i; 10 for(i=0;i<=9;i++) 11 ToHour['0'+i]=i; 12 for(i='A';i<='N';i++)

PAT (Advanced Level) 1061. Dating (20)

简单模拟. #include<stdio.h> #include<string.h> char s1[70],s2[70],s3[70],s4[70]; char f[7][5]={"MON ", "TUE ","WED ","THU ","FRI ","SAT ","SUN "}; int a,b,c,flag; int main() { s

pat1061. Dating (20)

1061. Dating (20) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Sherlock Holmes received a note with some strange strings: "Let's date! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm". It took him only a minut

PTA-C-4-7 统计某类完全平方数 (20分)

4-7 统计某类完全平方数   (20分) 本题要求实现一个函数,判断任一给定整数N是否满足条件:它是完全平方数,又至少有两位数字相同,如144.676等. 函数接口定义: int IsTheNumber ( const int N ); 其中N是用户传入的参数.如果N满足条件,则该函数必须返回1,否则返回0. 裁判测试程序样例: #include <stdio.h> #include <math.h> int IsTheNumber ( const int N ); int ma

PTA 10-排序4 统计工龄 (20分)

题目地址 https://pta.patest.cn/pta/test/15/exam/4/question/721 5-13 统计工龄   (20分) 给定公司NN名员工的工龄,要求按工龄增序输出每个工龄段有多少员工. 输入格式: 输入首先给出正整数NN(\le 10^5≤10?5??),即员工总人数:随后给出NN个整数,即每个员工的工龄,范围在[0, 50]. 输出格式: 按工龄的递增顺序输出每个工龄的员工个数,格式为:"工龄:人数".每项占一行.如果人数为0则不输出该项. 输入样

PTA 邻接表存储图的广度优先遍历(20 分)

6-2 邻接表存储图的广度优先遍历(20 分) 试实现邻接表存储图的广度优先遍历. 函数接口定义: void BFS ( LGraph Graph, Vertex S, void (*Visit)(Vertex) ); 其中LGraph是邻接表存储的图,定义如下: /* 邻接点的定义 */ typedef struct AdjVNode *PtrToAdjVNode; struct AdjVNode{ Vertex AdjV; /* 邻接点下标 */ PtrToAdjVNode Next; /*

6-1 单链表逆转(20 分)

6-1 单链表逆转(20 分) 本题要求实现一个函数,将给定的单链表逆转. 函数接口定义: List Reverse( List L ); 其中List结构定义如下: typedef struct Node *PtrToNode; struct Node { ElementType Data; /* 存储结点数据 */ PtrToNode Next; /* 指向下一个结点的指针 */ }; typedef PtrToNode List; /* 定义单链表类型 */ L是给定单链表,函数Rever

6-2 顺序表操作集(20 分)

6-2 顺序表操作集(20 分) 本题要求实现顺序表的操作集. 函数接口定义: List MakeEmpty(); Position Find( List L, ElementType X ); bool Insert( List L, ElementType X, Position P ); bool Delete( List L, Position P ); 其中List结构定义如下: typedef int Position; typedef struct LNode *List; str