一、AcWing 4399. 数字母
1、原题链接:AcWing 4399. 数字母
2、解题思路:
直接暴力干就完了!
3、参考代码:
#include<bits/stdc++.h>
using namespace std;
string s;
unordered_set<char> t;
int main(){
getline(cin,s);
int n = s.size();
for (int i = 0; i < n; i ++ ){
if(s[i]!='{' && s[i] != '}' && s[i] != ',' && s[i] != ' '){
t.insert(s[i]);
}
}
cout << t.size();
return 0;
}
二、4400. 玩游戏
1、原题链接:4400. 玩游戏
2、解题思路:
本题就是用一个队列来存放前n个数,然后将队头放到队尾,且删除现队头,完成队列的后移,为了避免循环次数变多,可以让a %= q.size()来减少循环次数,队列完成后移后,再先输出后删除队头元素即可。
3、参考代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int N = 110;
int n,m;
int main()
{
cin >> n >> m;
queue<int> q;
for(int i = 1; i <= n; i ++ ) q.push(i);
while( m -- ){
int a;
cin >> a;
//减少循环次数
a %= q.size();
for(int i = 0; i < a; i ++){
q.push(q.front());
q.pop();
}
cout << q.front() << ' ';
q.pop();
}
return 0;
}
三、AcWing 4401. 找回数组
1、原题链接:AcWing 4401. 找回数组
2、解题思路:
首先转换一下题中的式子:x[i]%k = a[i+1] -a[i]。若存在a[i] - a[i-1] != a[i-k] - a[i - k -1]则表示当前k值存在矛盾,应舍去。最后输出vector<int> res的大小以及其中的元素即可。
3、参考代码:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1010;
int a[N];
int n;
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
vector<int> res;
for(int k = 1; k <= n; k ++){
bool is_match = true;
for(int i = k + 1; i <= n; i ++){
if(a[i] - a[i-1] != a[i-k] - a[i - k -1]){
is_match = false;
break;
}
}
if(is_match) res.push_back(k);
}
cout << res.size() << endl;
for(auto k : res) cout << k << ' ';
return 0;
}