PAT甲级——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
考察内容是字符串处理。
这是很久之前的写法。
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char ans1[100],ans2[100],ans3[100],ans4[100];
const char week[7][7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
cin.get(ans1,100);
getchar();
cin.get(ans2,100);
getchar();
cin.get(ans3,100);
getchar();
cin.get(ans4,100);
getchar();
// printf("%s",ans1);
int len1=strlen(ans1);
int len2=strlen(ans2);
int len3=strlen(ans3);
int len4=strlen(ans4);
int i;
for(i = 0;i<len1&&i<len2;i++)
{
if(ans1[i]==ans2[i]&&ans1[i]>='A'&&ans1[i]<='G')
{
printf("%s ",week[ans1[i]-'A']);break;
}
}
for(i++;i<len1&&i<len2;i++)
{
if(ans1[i]==ans2[i])
{
if(ans1[i]>='0'&&ans1[i]<='9')
{
printf("%02d:",ans1[i]-'0');break;
}
else if(ans1[i]>='A'&&ans1[i]<='N')
{
printf("%02d:",ans1[i]-'A'+10); break;
}
}
}
for(int j=0;j<len3&&j<len4;j++)
{
if(ans3[j]==ans4[j]&&((ans3[j]>='A'&&ans3[j]<='Z')||(ans3[j]>='a'&&ans3[j]<='z')) )
{
printf("%02d",j);break;
}
}
return 0;
}
参考了柳婼解法,人家的解法是这个:
#include <iostream>
#include <cctype>
using namespace std;
int main() {
string a, b, c, d;
cin >> a >> b >> c >> d;
char t[2];
int pos, i = 0, j = 0;
while(i < a.length() && i < b.length()) {
if (a[i] == b[i] && (a[i] >= 'A' && a[i] <= 'G')) {
t[0] = a[i];
break;
}
i++;
}
i = i + 1;
while (i < a.length() && i < b.length()) {
if (a[i] == b[i] && ((a[i] >= 'A' && a[i] <= 'N') || isdigit(a[i]))) {
t[1] = a[i];
break;
}
i++;
}
while (j < c.length() && j < d.length()) {
if (c[j] == d[j] && isalpha(c[j])) {
pos = j;
break;
}
j++;
}
string week[7] = {"MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};
int m = isdigit(t[1]) ? t[1] - '0' : t[1] - 'A' + 10;
cout << week[t[0]-'A'];
printf("%02d:%02d", m, pos);
return 0;
}
PAT甲级——1061 Dating (20分)的更多相关文章
- PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)
1061 Dating (20 分) Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...
- PAT 甲级 1035 Password (20 分)(简单题)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for ...
- PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)
1077 Kuchiguse (20 分) The Japanese language is notorious for its sentence ending particles. Person ...
- PAT甲级——1061 Dating
1061 Dating Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2 ...
- 【PAT甲级】1061 Dating (20 分)
题意: 给出四组字符串,前两串中第一个位置相同且大小相等的大写字母(A~G)代表了周几,前两串中第二个位置相同且大小相等的大写字母或者数字(0~9,A~N)代表了几点,后两串中第一个位置相同且大小相等 ...
- PAT Basic 1014 福尔摩斯的约会 (20 分) Advanced 1061 Dating (20 分)
大侦探福尔摩斯接到一张奇怪的字条:我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm.大侦探很快就明白了,字条上奇 ...
- PAT甲级——1035 Password (20分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
- 1061 Dating (20分)
Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...
- PAT甲级1061 Dating
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805411985604608 题意: 给定四个字符串. 前两个字符串 ...
随机推荐
- Java 统计整数二进制中1的个数
package cookie; public class CountBinary_1 { public static void main(String[] args) { System.out.pri ...
- Bean 注解(Annotation)配置(1)- 通过注解加载Bean
Spring 系列教程 Spring 框架介绍 Spring 框架模块 Spring开发环境搭建(Eclipse) 创建一个简单的Spring应用 Spring 控制反转容器(Inversion of ...
- java嵌套循环练习
打印一个等腰三角形 package com.lv.jj; import java.util.Scanner; public class DemoDy { public static void main ...
- mybatis今年笔记
1.读取配置文件:用的就是解析Xml文件的技术 2.mybatis是支持自己写dao层的,但是没有必要. mybatis做的事情: 第一个创建代理对象,第二个在代理对象中调用方法. 3.相同的注解如果 ...
- 【LeetCode】课程表
[问题]现在你总共有 n 门课需要选,记为 0 到 n-1. 在选修某些课程之前需要一些先修课程.例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总量 ...
- Python之日志处理(logging模块)转载
本人主要做一个知识的归类与记录,如是转载类文章,居首都会备注原链接,尊重原创者,谢谢! 此文转载原链接:https://www.cnblogs.com/yyds/p/6901864.html 本节内容 ...
- bzoj 1009GT考试
做了上一道题,全程懵逼,再做这一道,,,23333继续 貌似那些东西都是差不多的.(参见cf621E) 这个为什么b[][]+=1很困惑,为什么不是从b[-1][??]转移的呢?想了一下,因为每一次都 ...
- Vue.js(20)之 封装字母表(是这个名字吗0.0)
HTML结构: <template> <div class="alphabet-container"> <h1>alphabet 组件</ ...
- 可重入排他锁ReentrantLock源码浅析
1.引子 "ReentrantLock"单词中的“Reentrant”就是“重入”的意思,正如其名,ReentrantLock是一个支持重入的排他锁,即同一个线程中可以多次获得同步 ...
- VMWare WorkStation15--Win10下开机启动虚拟机
参考 https://www.cnblogs.com/qmfsun/p/6284236.html http://www.cnblogs.com/eliteboy/p/7838091.html VMWa ...