problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing3607 命名空间参考

函数

int main (istream &cin, ostream &cout)
 
 TEST (acwing3607, case1)
 
 TEST (acwing3607, case2)
 

函数说明

◆ main()

int acwing::acwing3607::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing408.cpp161 行定义.

161 {
162 int year, day;
163 int day_of_month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
164 int day_of_month_leap[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
165 int start_day_of_month[14] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, INT_MAX};
166 while(cin >> year >> day) {
167 bool leap = (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
168 if(leap) {
169 for(int i = 1; i <= 12; i++) {
170 start_day_of_month[i] = start_day_of_month[i - 1] + day_of_month_leap[i - 1];
171 }
172 } else {
173 for(int i = 1; i <= 12; i++) {
174 start_day_of_month[i] = start_day_of_month[i - 1] + day_of_month[i - 1];
175 }
176 }
177 cout << setw(4) << setfill('0') << year << '-';
178 for(int i = 1; i <= 13; i++) {
179 if(start_day_of_month[i] > day) {
180 cout << setw(2) << setfill('0') << i - 1 << '-';
181 day -= start_day_of_month[i - 1];
182 day++;
183 cout << setw(2) << setfill('0') << day << endl;
184 break;
185 }
186 }
187 memset(start_day_of_month, 0, sizeof(start_day_of_month));
188 start_day_of_month[0] = 1;
189 start_day_of_month[13] = INT_MAX;
190 }
191 return 0;
192 }

被这些函数引用 TEST().

◆ TEST() [1/2]

acwing::acwing3607::TEST ( acwing3607  ,
case1   
)

在文件 acwing408_test.cpp538 行定义.

538 {
539 istringstream in("2000 3\n"
540 "2000 31\n"
541 "2000 40\n"
542 "2000 60\n"
543 "2000 61\n"
544 "2001 60");
545 auto out = ostringstream();
546 main(in, out);
547 const auto ans = out.str();
548 ASSERT_EQ("2000-01-03\n"
549 "2000-01-31\n"
550 "2000-02-09\n"
551 "2000-02-29\n"
552 "2000-03-01\n"
553 "2001-03-01\n",
554 ans);
555 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

acwing::acwing3607::TEST ( acwing3607  ,
case2   
)

在文件 acwing408_test.cpp557 行定义.

557 {
558 istringstream in("2000 3\n"
559 "2000 31\n"
560 "2000 40\n"
561 "2000 60\n"
562 "2000 366\n"
563 "2001 60\n"
564 "2004 366\n"
565 "1900 365");
566 auto out = ostringstream();
567 main(in, out);
568 const auto ans = out.str();
569 ASSERT_EQ("2000-01-03\n"
570 "2000-01-31\n"
571 "2000-02-09\n"
572 "2000-02-29\n"
573 "2000-12-31\n"
574 "2001-03-01\n"
575 "2004-12-31\n"
576 "1900-12-31\n",
577 ans);
578 }

引用了 main().