A.wwwvvvvvv
题意:遇到 w就 +2(因为 w 可以看成两个 v ) , 遇到遇到v 就 +1
AC代码:
#include <iostream>
#include <algorithm>
using namespace std;
string s;
int ans;
int main()
{
cin >> s;
for(int i = 0; i < s.size(); i ++)
{
if(s[i] == 'v') ans ++;
else ans += 2;
}
cout << ans << endl;
return 0;
}
B .LOOKU
题意:给出字符串S和T,问字符串T是不是字符串S的子串。
思路:如果字符串T的长度大于字符串S,那么字符串T一定不可能是字符串S的子串。否则,枚举字符串S每个字母开始的长度与字符串T相同的子串,判断是否与字符串T相同。
AC代码:
#include <iostream>
#include <algorithm>
using namespace std;
string s, t;
int ans, k;
int main()
{
cin >> s >> t;
int x = s.size(), y = t.size();
if(x < y)
{
cout << "No";
return 0;
}
for(int i = 0; i < x; i ++)
{
ans = 0;
k = i;
for(int j = 0; j < y; j ++)
{
if(s[k] == t[j])
{
k ++;
ans ++;
}
if(ans == y)
{
cout << "Yes";
return 0;
}
}
}
cout << "No";
return 0;
}
C .RANDOM
题意:给出 H 行 W 列的字符数组S和T,问是否有可能通过交换列使得这两个字符数组相同。
思路:只要将字符数组每列都存储一下,再通过枚举其中一个字符数组的列,寻找在另一个字符数组中是否有与其相同的列即可。
AC代码:
#include <iostream>
using namespace std;
const int N = 400010;
int num[N];
int h, w;
int main()
{
cin >> h >> w;
for (int i = 0; i < h; i ++)
{
for (int j = 0; j < w; j ++)
{
char s;
cin >> s;
if (s == '#')
{
num[i] ++;
}
}
}
bool flag = true;
for (int i = 0; i < h; i ++)
{
int tmp = 0;
for (int j = 0; j < w; j ++)
{
char t;
cin >> t;
if (t == '#')
{
tmp ++;
}
}
if (num[i] != tmp)
{
flag = false;
}
}
if (flag)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return 0;
}