1035. Password

来源:互联网 发布:c语言字符串数组拷贝 编辑:程序博客网 时间:2024/06/07 05:31

http://pat.zju.edu.cn/contests/pat-a-practise/1035

创建结构体存信息方便。

// #include <stdio.h>#include <string.h>#define SIZE 15#define MAXSIZE 1000+5void replace(char a[], char b[]){int i=0;while(a[i] != 0){switch(a[i]){case '1': b[i]='@'; break;case '0': b[i]='%'; break;case 'l': b[i]='L'; break;case 'O': b[i]='o'; break;default:b[i] = a[i];break;}i++;}}int main(){#ifdef ONLINE_JUDGE#elsefreopen("E:\\in.txt", "r", stdin);freopen("E:\\out.txt", "w", stdout);#endifint n;scanf("%d", &n);if(n == 1){puts("There is 1 account and no account is modified");return 0;}int m=0;char name[SIZE], pre[SIZE], after[SIZE];char buf[MAXSIZE][SIZE*2];memset(buf, 0, sizeof(buf));int num = n;while(num-->0){memset(name, 0, sizeof(name));memset(pre, 0, sizeof(pre));memset(after, 0, sizeof(after));scanf("%s %s", name, pre);replace(pre, after);if(strcmp(pre, after) != 0){strcpy(buf[m], name);strcat(buf[m], " ");strcat(buf[m], after);//strcat(buf[m], "\0");m++;}}if(m > 0){printf("%d\n", m);int i;for(i=0; i<m; i++){printf("%s\n", buf[i]);}}else{printf("There are %d accounts and no account is modified\n", n);}return 0;}


0 0
原创粉丝点击