当前位置:网站首页>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;
}边栏推荐
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机
- Adnroid activity截屏 保存显示到相册 View显示图片 动画消失
- Huawei's software and hardware ecosystem has taken shape, fundamentally changing the leading position of the United States in the software and hardware system
- PAT 乙等 1020.月饼
- PAT 乙等 1017 C语言
- Special research on Intelligent upgrading of heavy trucks in China in 2022
- MDM data cleaning function development description
- Real MySQL interview questions (25) -- common group comparison scenarios
- PAT 乙等 1021 个位数统计
- June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai
猜你喜欢

Special research on Intelligent upgrading of heavy trucks in China in 2022

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

最优传输理论下对抗攻击可解释性

Prometheus, incluxdb2.2 installation and flume_ Export download compile use

Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration

MySQL面试真题(二十七)——RFM分析法对用户进行分类

Management system of borrowed books based on SSM framework

Wechat applet: Puzzle toolbox

Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions

Behind the hot digital collections, a strong technical team is needed to support the northern technical team
随机推荐
jvm-01.指令重排
MySQL面试真题(二十九)——案例-找到爱看的电影
How can digital collections empower economic entities?
Data migration from dolphin scheduler 1.2.1 to dolphin scheduler 2.0.5 and data test records after migration
Pit filling for abandoned openssl-1.0.2 (.A to.So)
Three most advanced certifications, two innovative technologies and two outstanding cases, Alibaba cloud appeared at the cloud native industry conference
Wechat applet: elderly blessing short video
[image fusion] sparse regularization based on non convex penalty to realize image fusion with matlab code
制造业数字化转型存在问题及原因分析
数字藏品火热背后需要强大的技术团队支持 北方技术团队
Analysis on the problems and causes of digital transformation of manufacturing industry
The traditional Internet like platform may no longer exist, and a new industry integrating industrial characteristics and Internet characteristics
Real MySQL interview question (23) -- pinduoduo ball game analysis
Basic calculator II for leetcode topic analysis
The performance of nonstandard sprintf code in different platforms
What benefits have digital collections enabled the real industry to release?
True MySQL interview question (XXII) -- condition screening and grouping screening after table connection
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-7 personal solutions
啊哈C语言 第8章 游戏时间到了(第29讲)
C primer plus learning notes - 2. Constant and formatted IO (input / output)