题目链接
解题思路
新建一个结构体,包含一个标志位flag,然后遍历结构体数组,修改对应字符,计数,并修改结构体标志位。
注意
1、使用string& 引用来替换结构体中的字符串变量,引用指向了这个地址,所以修改引用即可修改对应字符,并且写起来非常简洁!
2、注意题目中的要求,N=1时要用单数,N>1时要用复数形式。
代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 #include <iostream> #include <cstdio> #include <string> using namespace std ;const int maxn=1010 ;struct Accout { string name,psw; bool flag; }accs[maxn]; int main () { int n,k=0 ; cin >>n; for (int i=0 ;i<n;i++){ cin >>accs[i].name>>accs[i].psw; accs[i].flag=false ; } for (int i=0 ;i<n;i++){ string & s=accs[i].psw; bool modi=false ; for (int j=0 ;j<s.length();j++){ if (s[j]=='1' ) { s[j]='@' ;modi=true ; } else if (s[j]=='0' ) { s[j]='%' ;modi=true ; } else if (s[j]=='l' ) { s[j]='L' ;modi=true ; } else if (s[j]=='O' ) { s[j]='o' ;modi=true ; } } if (modi){ k++; accs[i].flag=true ; } } if (k==0 ) { if (n==1 ) printf ("There is %d account and no account is modified" ,n); else printf ("There are %d accounts and no account is modified" ,n); } else { cout <<k<<endl ; for (int i=0 ;i<n;i++){ if (accs[i].flag){ cout <<accs[i].name<<" " <<accs[i].psw<<endl ; } } } return 0 ; }