A - Amateur Chess Players
水題,題面寫了一大堆,實際上有用的就幾句話,輸入也是,實際上有用的就只有n和m,就是比較n和m的大小
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long r = 1e9;
long long l = -r;
int n,m;
cin>>n;
string s;
for(int i = 0;i<n;i++){
cin>>s;
}
cin>>m;
for(int i = 0;i<m;i++){
cin>>s;
}
if(n==m){
cout<<"Quber CC";
}else if(n>m){
cout<<"Cuber QQ";
}else{
cout<<"Quber CC";
}
return 0;
}
F - Find / -type f -or -type d
近似模板題的字典樹,寫出來之後覺得非常簡單,但是其中也有好幾個坑。
題意就是說給一個原本輸入命令後給出的目錄及文件列表的亂序版本,讓你找到一共有幾個帶有.eoj後綴的文件,因爲是要找文件,所以如果在一個名字後面還有/文件名,那麼這個就是名字裏有.eoj的文件夾名,所以需要判斷一下這個是不是文件夾,如果不全部插入後再查找,需要排序後從後往前進行插入並查找,同時還需要判斷插入的字符串符不符合帶有.eoj的文件這一屬性。還有一種方法就是全部插入樹後,再對每一個字符串進行查找,看遍歷到最後的時候是否只出現過一次這個字符串。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;
const int N = 5e6 + 10;
string s[100005];
int tree[N][28];
int flag[N];
int cnt = 0;
map<string, int> q;
bool cmp(string s) {
int a = s.size();
return s[a - 1] == 'j' && s[a - 2] == 'o' && s[a - 3] == 'e' && s[a - 4] == '.' && a > 5 && s[a - 5] != '/';
}
int add(string s) {
int root = 0;
for (int i = 0; i < s.size(); i++) {
int id;
if (s[i] == '/') {
id = 26;
} else if (s[i] == '.') {
id = 27;
} else {
id = s[i] - 'a';
}
if (!tree[root][id]) {
tree[root][id] = ++cnt;
}
root = tree[root][id];
flag[root]++;
}
if (cmp(s) && flag[root] == 1) {
return 1;
} else {
return 0;
}
}
int main() {
ios::sync_with_stdio(false);
int n;
//solve();
cin >> n;
int ans = 0;
for(int i = 0;i<n;i++) {
cin >> s[i];
}
sort(s,s+n);
for(int i = n-1;i>=0;i--){
ans += add(s[i]);
}
cout << ans;
return 0;
}
I - Find / -type f -or -type d
也算是比較水的一道題,就是構造一個全部後綴子串按照字典序排序後,主串恰好排在k的字符串。這道題一開始想了好久,試了好多種構造方式,最後發現這種方法就可以了,有點崩潰。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;
void builds(){
int n,k;
string s;
cin>>n>>k;
for(int i = 1;i<=n;i++){
if(i==n-k+1){
s+='z';
}else{
s+='a';
}
}
cout<<s;
}
int main() {
ios::sync_with_stdio(false);
builds();
return 0;
}