这里推荐一位dalao的博客—— https://www.cnblogs.com/KisekiPurin2019/
A:字符串
B:贪心
A
// https://codeforces.com/contest/1281/problem/A
/*
暴力查找子序列
以最后的子序列为准
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int T;
char ch[1003];
char in[][10] = { "po", "desu", "masu", "mnida" };
char fin[][10] = { "FILIPINO", "JAPANESE", "KOREAN" };
int ans;
int main()
{
scanf("%d", &T);
while(T--){
scanf("%s", ch);
int len = strlen(ch);
for(int i = 0; i < len; i++){
if(len - i >= 2 && ch[i] == 'p' && ch[i + 1] == 'o') ans = 0;
if(len - i >= 4 && ((ch[i] == 'd' && ch[i + 1] == 'e' && ch[i + 2] == 's' && ch[i + 3] == 'u')
|| (ch[i] == 'm' && ch[i + 1] == 'a' && ch[i + 2] == 's' && ch[i + 3] == 'u'))) ans = 1;
if(len - i >= 5 && ch[i] == 'm' && ch[i + 1] == 'n' && ch[i + 2] == 'i' && ch[i + 3] == 'd' && ch[i + 4] == 'a') ans = 2;
}
printf("%s
", fin[ans]);
}
return 0;
}
B
// https://codeforces.com/contest/1281/problem/B
/*
题意:
可任意交换第一串字符串的b[i],b[j],使其字典序比第二串小
题解:
把b串的最小的字符提到前面来比较即可
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int n;
string b, c;
int main()
{
cin >> n;
while(n--){
cin >> b >> c;
int len = b.size();
// 每次把最小的最后面的字符串提到最前面来
for(int i = 0; i < len - 1; i++){
int minn = i + 1;
for(int j = minn + 1; j < len; j++){
if(b[j] <= b[minn]) minn = j; // 选最小的最后面的位置
}
if(b[minn] < b[i]){
swap(b[minn], b[i]);
break;
}
}
if(b < c)
cout << b << endl;
else cout << "---
";
}
return 0;
}
补题,没有rating。