1、数列分段
题目链接:https://sim.csp.thusaac.com/contest/5/problem/0
区分每一段的方法就是判断数列中的每一个数是否与前一个数相等。
100分代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{int n;cin >> n;int a[1010] = {1010};for(int i = 1; i <= n; i++){cin >> a[i];}int ans = 0;for(int i = 1; i <= n; i++){if(a[i] != a[i-1])ans++;}cout << ans << endl;return 0;
}
评测结果:
2、日期计算
题目链接:https://sim.csp.thusaac.com/contest/5/problem/1
言简意赅,按照题意模拟即可。
100分代码:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{int year,day;cin >> year >> day;int month1[12] = {31,28,31,30,31,30,31,31,30,31,30,31};int month2[12] = {31,29,31,30,31,30,31,31,30,31,30,31};int sum = 0; if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){for(int i = 0; i < 12; i++){sum += month2[i];if(sum >= day){cout << i+1 << endl;cout << day - (sum - month2[i]) << endl;break;}}} else {for(int i = 0; i < 12; i++){sum += month1[i];if(sum >= day){cout << i+1 << endl;cout << day - (sum - month1[i]) << endl;break;}}}return 0;
}
评测结果: