当前位置:网站首页>Pat class B 1014 C language
Pat class B 1014 C language
2022-06-23 05:54:00 【Octopus bro】
1014. Sherlock Holmes' date (20)
Sherlock Holmes received a strange note :“ let's date !3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”. The detective soon understood , The strange code on the note is actually the time of the date “ Thursday 14:04”, Because of the first two strings 1 For the same capital letters ( There is a distinction between case and case ) It's No 4 Letters 'D', On behalf of Thursday ; The first 2 For the same character is 'E', That's number one 5 English letters , It's the third day of the day 14 An hour ( So one day 0 Point to 23 Point by number 0 To 9、 And capital letters A To N Express ); After the second string 1 For the same English letters 's' Appear in the 4 A place ( from 0 Start counting ) On , On behalf of the 4 minute . Now give two pairs of strings , Please help Holmes decode the date .
Input format :
Enter in 4 Each line gives 4 One is not empty 、 No spaces 、 And the length shall not exceed 60 String .
Output format :
Output the appointment time in one line , The format is “DAY HH:MM”, among “DAY” It's a week's 3 Character abbreviations , namely MON For Monday ,TUE For Tuesday ,WED It means Wednesday ,THU It means Thursday ,FRI It means Friday ,SAT For Saturday ,SUN Means Sunday . Topic input ensures that each test has a unique solution .
sample input :3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnmsample output :
THU 14:04
Ideas : Set the week first : Find... In the first line of the string ‘A’-‘G’ The characters of , And the character at the same position as the second line , If equal, determine the week . Determine the hour , Continue to look backwards for numbers or... Based on the characters of the week ‘A’-‘N’ The letter of , Compare with the characters in the same position on the second line . Set the minutes , Look for the letters that appear in the third line of the string , Compare with the characters in the same position on the fourth line , Be careful , Here is the location .
One 、 Starting variable
1.a、b、c、d Four strings
2.count, Count variables , Used to determine which character is the same .
Two 、 operation
1. Set the week first : Find... In the first line of the string ‘A’-‘G’ The characters of , And the character at the same position as the second line , If equal, determine the week .
2. Determine the hour , Continue to look backwards for numbers or... Based on the characters of the week ‘A’-‘N’ The letter of , Compare with the characters in the same position on the second line .
3. Set the minutes , Look for the letters that appear in the third line of the string , Compare with the characters in the same position on the fourth line , Be careful , Here is the location .
3、 ... and 、 Code
#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;// It is used to count the number of the same characters ;
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
scanf("%s",d);
for(i = 0; i < strlen(a) && count <= 1; i++)
{
// Determine week : Find... In the first line of the string ‘A’-‘G’ The characters of , And the character at the same position as the second line , If equal, determine the week .
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++;
}
}
// Determine the hour , Continue to look backwards for numbers or... Based on the characters of the week ‘A’-‘N’ The letter of , Compare with the characters in the same position on the second line .
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;
}
}
}
// Set the minutes , Look for the letters that appear in the third line of the string , Compare with the characters in the same position on the fourth line , Be careful , Here is the location .
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;
}边栏推荐
- C primer plus learning notes - 2. Constant and formatted IO (input / output)
- PAT 乙等 1023 组个最小数
- Ansible 使用普通用户管理被控端
- PAT 乙等 1020.月饼
- Redis cache penetration solution - bloom filter
- PAT 乙等 1026 程序运行时间
- Excel sheet column number for leetcode topic resolution
- PAT 乙等 1016 C语言
- Yingjixin ip6806 wireless charging scheme 5W Qi certified peripheral simplified 14 devices
- C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)
猜你喜欢

TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机

jvm-03.jvm内存模型

Visdom draws multiple dynamic loss curves

Activity启动模式和生命周期实测结果

新课上线 | 每次 5 分钟,轻松玩转阿里云容器服务!

Redis cache penetration solution - bloom filter

技能自检 | 想当测试Leader,这6项技能你会吗?

Wireshark TS | 视频 APP 无法播放问题

android Handler内存泄露 kotlin内存泄露处理

Genetic engineering of AI art? Use # artbreeder to change any shape of the image
随机推荐
PAT 乙等 1016 C语言
Alibaba cloud object storage oss+picgo+typera implements the construction map
啊哈C语言 第8章 游戏时间到了(第29讲)
Yingjixin ip5566 with type-C port 3A charging and discharging fast charging mobile power supply 5W wireless charging in one SOC
Wireshark TS | 视频 APP 无法播放问题
Work accumulation - judge whether GPS is on
True MySQL interview question (24) -- row column exchange
AHA C language Chapter 8 game time is up (lesson 29)
Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators
Real MySQL interview questions (XXVII) -- Classification of users by RFM analysis method
使用链表实现两个多项式相加和相乘
Digital collections - new investment opportunities
PAT 乙等 1015 C语言
Leetcode topic resolution divide two integers
android Handler内存泄露 kotlin内存泄露处理
Lottery DDD code
C primer plus学习笔记 —— 2、常量与格式化IO(输入/输出)
Genetic engineering of AI art? Use # artbreeder to change any shape of the image
MySQL面试真题(二十九)——案例-找到爱看的电影
PAT 乙等 1019 C语言