T1
你的飞碟在这儿Your Ride Is Here
题意
给出两串字符串,它们的 A S C I I ASCII ASCII码的积如果 % 47 \%47 %47的结果相同就输出 “ G O ” “GO” “GO”,否则输出 “ S T A Y " “STAY" “STAY"。
思路
简单的模拟,这里就不再讲了。
代码
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char a[7], b[7];
int a1, b1, l1, l2;
int main() {
scanf("%s", a);
scanf("%s", b);
a1 = a[0] - 64;
b1 = b[0] - 64;
l1 = strlen(a);
l2 = strlen(b);
for (int i = 1; i < l1; i++) a1 *= a[i] - 64;
for (int i = 1; i < l2; i++) b1 *= b[i] - 64;
if (a1 % 47 == b1 % 47) printf("GO");
else printf("STAY");
}
T2
贪婪的送礼者Greedy Gift Givers
思路
根据题意模拟,用 m a p map map来统计他们的钱。
代码
#include<map>
#include<cstdio>
#include<string>
#include<iostream>
using namespace std;
string name[12], s, person;
map<string, int> cnt;
int N, money, p, num;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++)
cin>>name[i];
for (int i = 1; i <= N; i++) {
cin>>s;
scanf("%d %d", &money, &p);
if (p) num = money / p;
else num = 0;
cnt[s] -= num * p;
for (int j = 1; j <= p; j++) {
cin>>person;
cnt[person] += num;
}
}
for (int i = 1; i <= N; i++)
cout<<name[i]<<" "<<cnt[name[i]]<<endl;
}
T3
黑色星期五Friday the Thirteenth
题意
已知 1900 1900 1900年 1 1 1月 1 1 1日是星期一,求出 1900 1900 1900年到 1900 + N − 1 1900+N-1 1900+N−1年的 12 12 12月 31 31 31日中 13 13 13号落到每个星期的天数,从星期六开始输出。
思路
一天一天地加,判断再统计。
代码
#include<cstdio>
int ans[8], yue[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check_year(int y){
if(y % 100 == 0 && y % 400) return 0;
if (y % 4 == 0) return 1;
return 0;
}
int main(){
int N;
scanf("%d", &N);
for (int year = 1900, month = 1, day = 1, week = 1; ;){
if(year == 1900 + N && month == 1 && day == 1) break;
day++;
week++;
if(check_year(year)) yue[2] = 29;
else yue[2] = 28;//判断平年闰年
if(day > yue[month]){//天重置
day = 1;
month += 1;
}
if(month > 12){//月重置
year += 1;
month = 1;
}
if(week > 7) week = 1;
if(day == 13) ans[week] += 1;
}
printf("%d %d %d %d %d %d %d", ans[6], ans[7], ans[1], ans[2], ans[3], ans[4], ans[5]);
}
T4
坏掉的项链Broken Necklace
题意
一个链,选择从一个地方断开,从头和尾开始取两端相同颜色的珠子(白色可以代表任意颜色),求出能取出的最长的长度。
思路
复制两倍然后枚举断点统计。
代码
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char a[701];
int N, ans = -1;
int count(int w) {//统计
int _ = 0, __ = 0;
int i = w, j = w + N - 1;
char c;
while (a[i] == 'w') i++, _++;
while (a[j] == 'w') j--, __++;
c = a[i];
for (; i <= w + N - 1; i++) {//头
if (a[i] != c && a[i] != 'w') break;
_++;
}
c = a[j];
for (; j >= w; j--) {//尾
if (a[j] != c && a[j] != 'w') break;
__++;
}
return _ + __;
}
int main() {
scanf("%d", &N);
cin>>a + 1;
for (int i = 1; i <= N; i++) a[i + N] = a[i];
for (int i = 1; i <= N; i++) {
if (a[i] == a[i - 1]) continue;
ans = max(ans, count(i));
}
ans = min(ans, N);
printf("%d", ans == -1 ? N : ans);
}