题目描述
为了缓解交通压力、减少空气污染,B市市政府决定在工作日(周一至周五)对机动车进行限行,每辆机动车每周将有一个工作日不能出行,但周末不限行。假设该政策从2000年1月1日起开始执行。限行安排为:
尾号为1和6:周一限行
尾号为2和7:周二限行
尾号为3和8:周三限行
尾号为4和9:周四限行
尾号为5、0和字母:周五限行
已知2000年1月1日为周六,现在给出一些日期和车牌号,求问该机动车在该天是否限行。
关于输入
输入第一行为一个整数n(1<=n<=100),表示测试的组数。
之后输入n行,每一行由一个日期和一个车牌号组成,用空格分隔。日期的格式为“2000-01-23”,日期保证在2000年1月1日~9999年12月31日之间;车牌号的格式为6位字符串,由数字和大写字母组成,例如“A123Q6”。
关于输出
输出共n行,对于每一组测试输出一行。如果给出的车辆在给出日期限行,则输出“yes”,否则输出“no”。
输入例子“4997-11-01 XV23X7”的时候,输出的是“28271”
#include
#include
using namespace std;
int f(int x, int y, int z) //寻找天数
{
int t[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 },sum=z;
for (int i = 2000; i < x; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
sum += 366;
else sum += 365;
}
if ((x % 4 == 0 && x % 100 != 0) || x % 400 == 0)t[1] = 29;
for (int j = 0; j < y - 1; j++)
sum += t[j];
return sum;
}
void g(int h, char s) //判断是否限行
{
if (s == '1' || s == '6')
{
if (h == 3)cout << "yes"<else cout << "no"<else if (s == '2' || s == '7')
{
if (h == 4)cout << "yes"<else cout << 'no'<else if (s == '3' || s == '8')
{
if (h == 5)cout << "yes"<else cout << "no"<else if (s == '4' || s == '9')
{
if (h == 6)cout << "yes"<else cout << "no"<else
{
if (h == 0)cout << "yes"<else cout << "no"<int main()
{
int n;
cin >> n;
int year, month, day;
char a, b,d[6];
while (n>0)
{
cin >> year >> a >> month >> b >> day;
for (int i = 0; i < 6; i++)cin >> d[i];
int m = f(year, month, day);
int t = m % 7;
g(t, d[5]);
n--;
}
return 0;
}