简单题,第一次读错题,忘了要先输出有几个改的
↓忘了加计数的
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int n, sum;
bool key = false;
int main(){
scanf("%d",&n);
for(int i=0; i<n; i++){
string a;
char arr[15];
bool k = false;
cin >> a >> arr;
int l = strlen(arr);
for(int j=0; j<l; j++){
if(arr[j] == '1') { arr[j] = '@'; k = true;}
if(arr[j] == '0') { arr[j] = '%'; k = true;}
if(arr[j] == 'l') { arr[j] = 'L'; k = true;}
if(arr[j] == 'O') { arr[j] = 'o'; k = true;}
}
if(k == true) {
cout << a << " ";
for(int t=0; t<l; t++) cout << arr[t] ;
cout << endl;
key = true;
}
}
if(key != true) printf("There are %d accounts and no account is modified\n",sum);
return 0;
}
发现之后不知道怎么存储
还是要巧妙运用string
同时注意特殊点:输出注意单复数 还有 is are
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n, sum;
bool key = false;
vector<string> ans;
int main(){
scanf("%d",&n);
for(int i=0; i<n; i++){
string a;
string arr;
bool k = false;
cin >> a >> arr;
int l = arr.length();
for(int j=0; j<l; j++){
if(arr[j] == '1') { arr[j] = '@'; k = true;}
if(arr[j] == '0') { arr[j] = '%'; k = true;}
if(arr[j] == 'l') { arr[j] = 'L'; k = true;}
if(arr[j] == 'O') { arr[j] = 'o'; k = true;}
}
if(k == true) {
string b = a + " " + arr;
ans.push_back(b);
key = true;
}
else sum++;
}
if(key != true) {
if(sum == 1) printf("There is 1 account and no account is modified\n");
else printf("There are %d accounts and no account is modified\n",sum);
}
else {
int m = ans.size();
cout << m << endl;
for(int p=0; p<m; p++) cout << ans[p] << endl;
}
return 0;
}