* 1014. Sherlock Holmes's appointment

Source: Internet
Author: User
1/* 2 * Main. C 3*1014. sherlock Holmes appointment 4 * created on: September 1, 2014 5 * Author: in the boomkeeper 6 ***** section, ********** 7 */8 9 # include <stdio. h> 10 # include <string. h> 11 12/* 13 * Find "day" and "hh" 14 */15 void find_day_hour (const char str1 [] in "day hh: mm", const char str2 []) {16 17 int len1 = strlen (str1); 18 int len2 = strlen (str2); 19 int I; 20 char tempday, temphour; // store day and hh21 char hour [24] = {'0', '1', '2', '3', '4', '5 ',' 6', '7', '8', '9', 22 'A', 'B', 'C', 'D', 'E', 'F ', 'G', 'h', 'I', 'J', 'k', 'l', 'M', 'n '}; 23 24 // find day25 for (I = 0; I <(len1 <len2? Len1: len2); I ++) {26 if (str1 [I] = str2 [I]) & (str1 [I] <= 'G' & str1 [I]> = 'A') {27 tempday = str2 [I]; 28 break; 29} 30} 31 32 // calculate the day and print the 33 switch (tempday) {34 case 'A': printf ("mon"); break; 35 case 'B ': printf ("Tue"); break; 36 case 'C': printf ("wed"); break; 37 Case 'D': printf ("Thu"); break; 38 case 'E': printf ("fri"); break; 39 case 'F': printf ("sat"); break; 40 case 'G ': printf ("Sun" ); Break; 41} 42 43 // locate hh44 for (I + = 1; I <(len1 <len2? Len1: len2); I ++) {45 if (str1 [I] = str2 [I]) & (str1 [I]> = '0' & str1 [I] <= '9 ') | (str1 [I]> = 'A' & str1 [I] <= 'n') {46 temphour = str2 [I]; 47 break; 48} 49} 50 51 // calculate hh52 for (I = 0; I <24; I ++) {53 If (hour [I] = temphour) {54 // print hour 55 printf ("% 02i:", I); 56 break; 57} 58} 59} 60 61/* 62 * Find "day hh: "mm" 63 */64 void find_min (const char str3 [], const char str4 []) {65 66 int len3 = strlen (str3); 67 int Len4 = strlen (str4); 68 int I; 69 70 for (I = 0; I <(len3 <len4? Len3: len4); I ++) {71 If (str3 [I] <= 'Z' & str3 [I]> = 'A ') & (str4 [I] <= 'Z' & str4 [I]> = 'A') 72 If (str3 [I] = str4 [I]) 73 break; 74} 75 76 // print min 77 printf ("% 02i \ n", I); 78} 79 80 int main (void) {81 82 char str1 [60], str2 [60], str3 [60], str4 [60]; 83 84 gets (str1); 85 gets (str2 ); 86 gets (str3); 87 gets (str4); 88 89 find_day_hour (str1, str2); 90 find_min (str3, str4); 91 92 return 0; 93}

 

I had a hard time thinking about this question for a day. I still had to be patient. A pair of <= logical operators and curly braces almost drove me crazy!

 

Question link:

Http://pat.zju.edu.cn/contests/pat-b-practise/1014

 

 

.

* 1014. Sherlock Holmes's appointment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.