C 古老的恩尼格玛机
题意:给你26个大写字母,其中第i个和第i+1个是一对转换关系。输入字符串,输出转换之后的字符串。
分析:使用map存放转换关系,输出即可。
题解:
#include<bits/stdc++.h>
using namespace std;
map<char,char> mp;
int main()
{
for(int i=0;i<13;i++)
{
char x,y;
cin >> x >> y;
mp[x] = y;
mp[y] = x;
}
int t;
cin >> t;
while(t--)
{
string s;
cin >> s;
for(int i=0;i<s.length();i++)
{
cout << mp[s[i]];
}
cout << " ";
}
return 0;
}
D 并不智能的卡牌 AI
题意:m张反着的卡牌,每次最多可以翻n张,问多少步操作把所有的牌反过来。
分析:特判m = 0, 和 n = 0的情况,计算m / n向上取整。
题解:
#include<bits/stdc++.h>
using namespace std;
int main()
{
double m ,n;
cin >> m >> n;
if(m==0)
{
cout << 0 << endl;
return 0;
}
if(n==0)
{
cout << -1 << endl;
return 0;
}
else
{
cout << ceil(m/n) << endl;
}
return 0;
}
H 差不多得了
题意:给你n个数,总和为a。判断有几个子序列的和是a-1。
分析:只要有不连续的1,就有多少种子序列满足。
题解:
#include<bits/stdc++.h>
using namespace std;
int a[50];
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
for(int i=1;i<=n;i++)
cin >> a[i];
int cnt = 0;
for(int i=1;i<=n;i++)
{
if(a[i] == 1 && a[i-1] != 1)
cnt++;
}
cout << cnt << endl;
}
return 0;
}