题目链接在此。
题意理解
给定N个用户的用户名(name)和密码(pwd),现在需要按照如下修改规则,对需要修改密码的用户信息进行修改,修改规则如下:
1(数字1) ->@
0(数字0) ->%
l(小写L) ->L
O(大写字母O) ->o(小写字母o)
之后,输出修改过的用户信息的个数和对应的信息(用户名 密码)
如果没有任何用户的信息得到了修改,则根据单复数输出”There is(are) N account(s) and no account is modified”
以上加粗就是需要注意的地方。
思路
定义INFO结构体数组(包含name字符数组和pwd字符数组),申请一个零时的INFO变量temp,用它来保存每次的输入;定义一个INFO型数组info[],将修改过后的用户信息存入其中。之后根据题意输出即可。
AC代码
#include<stdio.h>
#include<string.h>
struct INFO{
char name[11];
char pwd[11];
}info[1001];
int main(){
INFO temp;
int N;
int M = 0;
scanf("%d",&N);
bool flag; //是否modify的标志
for(int i = 0 ; i < N; i++){
scanf("%s %s",temp.name,temp.pwd);
flag = false;
//modify
for(int j = 0; j < strlen(temp.pwd); j++){
if(temp.pwd[j] == '1'){
temp.pwd[j] = '@';
flag = true;
}else if(temp.pwd[j] == '0'){
temp.pwd[j] = '%';
flag = true;
}else if(temp.pwd[j] == 'l'){
temp.pwd[j] = 'L';
flag = true;
}else if(temp.pwd[j] == 'O'){
temp.pwd[j] = 'o';
flag = true;
}
}
//& if modified, put it into info[]
if(flag){
info[M++] = temp;
}
}
if(M==0){
if(N==1)
printf("There is %d account and no account is modified\n",N);
else
printf("There are %d accounts and no account is modified\n",N);
} else{
printf("%d\n",M);
for(int i = 0; i < M; i++){
printf("%s %s\n",info[i].name,info[i].pwd);
}
}
return 0;
}