Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
EDITORIAL
- Ideas analysis
- After adjusting an array of strings in the string change vector plane memory ⾥
- The number of array elements which is 0 or select a different logic branches
- Outputting corresponding results
- Simple title, 10 minutes a title
Test Case
-
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 accounts and no account is modified
ac Code
-
#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; }
Knowledge Point Summary
- String find and replace
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)