代码如下:
/* * *Declaration:The author of <<Accelerated C++>> has wrote in the end of that book: As you look for reading materimal, keep in mind that books on the shelf do not make you a better programmer. Ultimately, the only way to improve your programming is to write programs. >这些程序来自一些ACM书籍,作者只为提高编程能力,实现书中例题或练习。如有侵权,请联系作者,作者将立即删除。 * *联系邮箱:mingxinglai#gmail.com * */ #include <stdio.h> int main(int argc, char* argv[]) { int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int n; scanf("%d", &n); for( int i = 0; i < n; i++) { int month_1, day_1, month_2, day_2, num; scanf("%d%d%d%d%d", &month_1, &day_1, &num, &month_2, &day_2); int sum = 0; for( int k = month_1; k < month_2; k++) sum += days[ k - 1 ]; sum -= day_1; sum += day_2; int nNum = num; for(int k = 0; k < sum; k++) nNum *= 2; printf("%d\n", nNum); } return 0; }示例2:(较上面的代码更为简洁明了)
#include <stdio.h> int month[]= {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main(int argc, char* argv[]) { int times; scanf("%d", ×); int mon1, date1, mon2, date2, num; while( times-- ) { scanf("%d%d%d%d%d", &mon1, &date1, &num, &mon2, &date2); int days = date2 - date1; for( int i = mon1; i < mon2; i++) days += month[i]; long nNum = num; for( int j = 0; j < days; j++) num *= 2; printf("%d\n", num); } return 0; }