当前位置:网站首页>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&Hyscvnm
sample 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;
}



原网站

版权声明
本文为[Octopus bro]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230410348208.html