写在前面
- 思路分析
- 待调整字符串改变后存储在字符串数组vector⾥面
- 数组里面元素的个数是否为0选择不同逻辑分支
- 输出相应结果
- 题目简单,10分钟a题
测试用例
input:
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
output:
2
Team000002 RLsp%dfa
Team000001 R@spodfa
input:
1
team110 abcdefg332
output:
There is 1 account and no account is modified
input:
2
team110 abcdefg222
team220 abcdefg333
output:
There are 2
ac代码
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<string> v;
for(int i=0; i<n; i++)
{
string name, s;
cin >> name >> s;
int len = s.length(), flag = 0;
for(int j=0; j<len; j++)
{
switch(s[j])
{
case '1' :
s[j] = '@';flag = 1;break;
case '0' :
s[j] = '%';flag = 1;break;
case 'l' :
s[j] = 'L';flag = 1;break;
case 'O' :
s[j] = 'o';flag = 1;break;
}
}
if(flag)
{
string tmp = name + " " + s;
v.push_back(tmp);
}
}
int cnt = v.size();
if(cnt != 0)
{
printf("%d\n", cnt);
for(int i=0; i<cnt; i++)
cout << v[i] << endl;
}
else if(n==1)
printf("There is 1 account and no account is modified");
else
printf("There are %d accounts and no account is modified", n);
return 0;
}
知识点小结
- 字符串查找、替换
-
s.replace(pos, n, s1) 用s1替换s中从pos开始(包括0)的n个字符的子串
string ss = "Rlsp0dfa";
if(ss.find('0'))
cout << ss.replace(4, 1, "%") << endl;
s.find(s1) 查找s中第一次出现s1的位置,并返回(包括0)
s.rfind(s1) 查找s中最后次出现s1的位置,并返回(包括0)