当前位置:网站首页>PAT 乙等 1014 C语言
PAT 乙等 1014 C语言
2022-06-23 04:11:00 【章鱼bro】
1014. 福尔摩斯的约会 (20)
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧!3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是第4个字母'D',代表星期四;第2对相同的字符是'E',那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、以及大写字母A到N表示);后面两字符串第1对相同的英文字母's'出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。
输入格式:
输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。
输出格式:
在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
输入样例:3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm输出样例:
THU 14:04
思路:先确定星期:在第一行字符串中找到‘A’-‘G’的字符,和第二行相同位置的字符进行判断,若相等确定星期。再确定小时,在确定了星期的字符基础上继续向后寻找数字或者‘A’-‘N’的字母,与第二行相同位置字符进行比较。确定分钟,在第三行字符串中寻找出现的字母,与第四行相同位置的字符进行比较,注意,此处要的是位置。
一、起始变量
1.a、b、c、d四个字符串
2.count,计数变量,用来判断是第几个相同的字符。
二、运算
1.先确定星期:在第一行字符串中找到‘A’-‘G’的字符,和第二行相同位置的字符进行判断,若相等确定星期。
2.再确定小时,在确定了星期的字符基础上继续向后寻找数字或者‘A’-‘N’的字母,与第二行相同位置字符进行比较。
3.确定分钟,在第三行字符串中寻找出现的字母,与第四行相同位置的字符进行比较,注意,此处要的是位置。
三、代码
#include "stdio.h"
#include "string.h"
typedef char String[4];
int main()
{
String week[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
char a[60],b[60],c[60],d[60];
int i, j;
int count = 0;//用来统计是第几个相同的字符;
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
scanf("%s",d);
for(i = 0; i < strlen(a) && count <= 1; i++)
{
//确定星期:在第一行字符串中找到‘A’-‘G’的字符,和第二行相同位置的字符进行判断,若相等确定星期。
if(count == 0 && a[i] >= 'A' && a[i] <= 'G' )
{
if(a[i] == b[i])
{
int num = a[i] - 'A';
printf("%s ",week[num]);
i++;
count++;
}
}
//确定小时,在确定了星期的字符基础上继续向后寻找数字或者‘A’-‘N’的字母,与第二行相同位置字符进行比较。
if(count == 1 && a[i] >= '0' && a[i] <= '9' )
{
if(a[i] == b[i])
{
printf("0%d:",a[i] - '0');
break;
}
}
else if(count == 1 && a[i] >= 'A' && a[i] <= 'N' )
{
if(a[i] == b[i])
{
printf("%d:",a[i] - 55);
break;
}
}
}
//确定分钟,在第三行字符串中寻找出现的字母,与第四行相同位置的字符进行比较,注意,此处要的是位置。
for( i = 0; i < strlen(c); i++)
{
if((c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'))
{
if(c[i] == d[i])
{
if(i < 10)
{
printf("0%d",i);
break;
}
else
{
printf("%d",i);
break;
}
}
}
}
return 0;
}边栏推荐
- ArcTime 制作中英文字幕视频
- Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
- 技能自检 | 想当测试Leader,这6项技能你会吗?
- MDM数据清洗功能开发说明
- Shutdown shutdown command
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-9 personal solutions
- MySQL面试真题(二十九)——案例-找到爱看的电影
- CF [1700d] D. River locks (DP, bisection, Mathematics)
- MySQL面试真题(三十)——贝壳-房产订单分析
- True question of MySQL interview (29) -- case - finding favorite movies
猜你喜欢

Is there a real part-time job online? How do college students find part-time jobs in summer?

Lottery DDD code

STC 32位8051单片机开发实例教程 一 开发环境搭建

C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
![[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code](/img/e2/24eb2a60e3dc603b3ec4bfefd0b8e5.png)
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code

C primer plus learning notes - 2. Constant and formatted IO (input / output)

Management system of borrowed books based on SSM framework

51万奖池邀你参战——第二届阿里云ECS CloudBuild开发者大赛来袭

Composite API

MDM数据清洗功能开发说明
随机推荐
ArcTime 制作中英文字幕视频
Lottery DDD code
Use of visdom
Implementation of MySQL custom sequence number
Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents
[proteus simulation] Arduino uno+pcf8574+lcd1602+mpx4250 electronic scale
Heimdall database proxy scale out 20 times
ORB_SLAM2运行
Digital collections - new investment opportunities
STC 32 Bit 8051 Single Chip Computer Development Example Tutorial one development environment
MySQL面试真题(二十七)——RFM分析法对用户进行分类
mysql字符集
AHA C language Chapter 8 game time is up (lesson 29)
Alibaba cloud object storage oss+picgo+typera implements the construction map
Is there a real part-time job online? How do college students find part-time jobs in summer?
Jsonfield annotation in fastjson
制造业数字化转型存在问题及原因分析
使用链表实现两个多项式相加和相乘
PAT 乙等 1026 程序运行时间
英文字母pc是什么意思,互联网的pc指的是什么