当前位置:网站首页>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;
}边栏推荐
- Ip6809 three coil 15W wireless charging transmitter scheme IC British chip
- 啊哈C语言 第7章 有了它你能做更多的事(第27-28讲)
- B-string value (string DP) of the 16th Northeast College Students' Programming Competition (warm-up)
- The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet
- 电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办
- Arctime makes Chinese and English subtitle video
- 【数据库备份】通过定时任务完成MySQL数据库的备份
- runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
- 数字藏品赋能实体产业释放了哪些利好?
- Differences between fs4059a and fs5080e charging chips
猜你喜欢

STC 32-bit 8051 MCU development example tutorial I development environment construction

The road of architects starts from "storage selection"

Skill self check | do you know these 6 skills if you want to be a test leader?

数字藏品赋能实体产业释放了哪些利好?

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

App automated test appium advanced

What benefits have digital collections enabled the real industry to release?

数字藏品市场才刚刚开始

What if win11 cannot record audio? Solution of win11 unable to input sound

Lihongyi, machine learning 5 Tips for neural network design
随机推荐
The 510000 prize pool invites you to participate in the competition -- the second Alibaba cloud ECS cloudbuild developer competition is coming
MySQL面试真题(二十六)——滴滴2020年笔试题
Skill self check | do you know these 6 skills if you want to be a test leader?
Shutdown shutdown command
Export PDF with watermark
A bit of knowledge - folding forging and Damascus steel
ORB_SLAM2运行
MySQL面试真题(二十九)——案例-找到爱看的电影
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
英集芯推出4串锂电池100W移动电源升降压方案SoC芯片IP5389
Yingjixin ip6806 wireless charging scheme 5W Qi certified peripheral simplified 14 devices
FS2119A同步升压IC输出3.3V和FS2119B同步升压IC输出5V
数字藏品市场才刚刚开始
fastjson中的@JSONField注解
SIFT feature point extraction
Pkav simple blasting
Win11如何开启移动热点?Win11开启移动热点的方法
Jsonfield annotation in fastjson
Ansible 使用普通用户管理被控端
制造业数字化转型存在问题及原因分析