CCF201509-2 日期计算

it2022-05-05  108

// DateCalculation.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "iostream" #include "windows.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { DWORD start_time = GetTickCount(); //Start timer int y=2015, d=80; //cin >> y; cin >> d; int m=1, days; int md[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)) md[1] = 29; int sum=0,temp; for (int i = 0; i < 12;i++) { sum += md[i]; if (sum>=d) { days = d - temp; break; } else { m++; } temp = sum; } cout << m << endl; cout << days << endl; DWORD end_time = GetTickCount(); //End timer cout << "The run time is:" << (end_time - start_time) << "ms!" << endl; //Output run time return 0; }

 


最新回复(0)