43: Related month, 43 related month

Source: Internet
Author: User

43: Related month, 43 related month
43: Related month

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

"Related month" refers to the months with the same number of stars on the first day of the month of the year. For example, September is related to December, because the number of weeks in September 1 and December 1 is always the same. It is related to two months. If the number of days on the first day of the two months is 7, the difference between the two months is several whole weeks. Another example is that July 15 and July 15 are related months, because July 15 has 28 days and can be divided by 7, which is exactly four weeks. In a leap year, the related months in January and February are different from those in the year of the year. Because there are 29 days in February, the number of stars on the first day of each month is pushed back to the next day.

Input
The first input behavior integer n (n ≤ 200 ),
The next n rows have three integers in each line, which are one year and two months in sequence. integers are separated by a space.
Output
The output contains n rows, corresponding to each input year and the corresponding two months,
If the two months are related, the output is YES;
Otherwise, NO is output.
Sample Input
51994 10 91935 12 11957 1 91917 9 121948 1 4
Sample output
NONONOYESYES
Source
Beijing University Medical Science Department computing overview 08 final exam questions
1 # include <iostream> 2 using namespace std; 3 int month [21] = {, 31, 31 }; // non-leap year 4 int rmonth [21] = {0, 31, 29,31, 30,31, 30,31, 31,30, 31,30, 31}; // leap year 5 int flag = 1; 6 int main () 7 {8 int n; 9 int year; 10 int month1; 11 int mon2; 12 cin> n; 13 for (int I = 1; I <= n; I ++) 14 {15 cin> year> month1> mon22. 16 if (month1> mon22.) 17 {18 int d = month1; month1 = mon22. mon2nd = d; 19} 20 if (year % 4 = 0 & ye Ar % 100! = 0) | year % 400 = 0) 21 {22 int begin = 1; // The default first day is Monday 23 for (int j = month1; j <= month2-1; j ++) 24 {25 for (int k = 1; k <= rmonth [j]; k ++) 26 {27 if (begin = 7) 28 begin = 1; 29 else 30 begin ++; 31 32} 33 34} 35 if (begin = 1) 36 cout <"YES" <endl; 37 else38 cout <"NO" <endl; 39} // leap year 40 else41 {42 int begin = 1; // The default first day is Monday 43 for (int j = month1; j <= month2-1; j ++) 44 {45 for (int k = 1; k <= month [j]; k ++) 46 {47 if (begin = 7) 48 begin = 1; 49 else begin ++; 50} 51} 52 if (begin = 1) 53 cout <"YES" <endl; 54 else55 cout <"NO" <endl; 56} // non-leap year 57} 58 return 0; 59}

 

Related Article

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.