日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【最详细的分析】1061 Dating (20 分)

發布時間:2024/2/28 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【最详细的分析】1061 Dating (20 分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

立志用最少的代碼做最高效的表達


PAT甲級最優題解——>傳送門


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


題意:

判斷星期: 大寫字母相等, 并且必須是A-G之間的字母。

判斷小時:如果是數字,那么在0-9之間, 如果是字母,那么在A-N之間,分別代表0-23點

判斷分鐘:必須是字母相等, 大寫小寫都可以, 可以用isalpha()函數判斷。

注意:

1、 小時和分鐘都要有前導0, 也就是如3小時要輸出03.

2、判斷星期后,要及時break或continue, 避免判斷星期的字母被當成判斷小時的字母再讀一次(測試點二)


#include<bits/stdc++.h> using namespace std; int main() {//建立映射 unordered_map<char, string>week;unordered_map<char, int> hour;week['A']="MON"; week['B']="TUE"; week['C']="WED"; week['D']="THU"; week['E']="FRI"; week['F']="SAT"; week['G']="SUN";for(char i = '0'; i <= '9'; i++) hour[i] = i-'0';for(char i = 'A', k = 10; i <= 'N'; i++, k++) hour[i] = k;string s1, s2, s3, s4;cin >> s1 >> s2 >> s3 >> s4;int len = min(s1.size(), s2.size());bool flag = false;for(int i = 0; i < len; i++) {if(s1[i] == s2[i]) if(!flag) { //輸出星期 if(week.count(s1[i]) > 0) {cout << week[s1[i]] << ' ';flag = true;}}else { //輸出小時 if(hour.count(s1[i]) > 0) {printf("%02d:", hour[s1[i]]); break; //切記切記, 輸出完小時候要及時break。 否則測試點2會報錯。 }}} int len1 = min(s3.size(), s4.size());//輸出字母 for(int i = 0; i < len1; i++) if(s3[i] == s4[i] && isalpha(s3[i])) printf("%02d", i);return 0; }

耗時:


求贊哦~ (?ω?)

總結

以上是生活随笔為你收集整理的【最详细的分析】1061 Dating (20 分)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。