解题思路: 利用数组存放星期几,较少代码重复量
注意事项: 注意每次都要循环都要进行%取余运算,不然会造成越界
参考代码:
#include<iostream>
using namespace std;
int main()
{
string arr[7] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
int sum = 1;
int a, b;
cin >> a >> b;
for (int i = 0; i < b; ++i) {
sum *= a;
sum %= 7;
}
cout << arr[sum] << endl;
system("pause");
return 0;
}
0.0分
1 人评分
【绝对值排序】 (C语言代码)浏览:832 |
A+B for Input-Output Practice (V) (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:624 |
【排队买票】 (C语言代码)浏览:944 |
杨辉三角 (C语言代码)浏览:504 |
C二级辅导-等差数列 (C语言代码)浏览:806 |
C二级辅导-阶乘数列 (C语言代码)浏览:583 |
程序员的表白 (C语言代码)浏览:678 |
Quadratic Equation (C语言代码)浏览:1034 |
简单的a+b (C语言代码)浏览:683 |