PAT甲级1035

LZ1225 2016-05-23 11:28:19
1035. Password (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N (<= 1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

Output Specification:

For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line "There are N accounts and no account is modified" where N is the total number of accounts. However, if N is one, you must print "There is 1 account and no account is modified" instead.

Sample Input 1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa
Sample Output 1:
2
Team000002 RLsp%dfa
Team000001 R@spodfa
Sample Input 2:
1
team110 abcdefg332
Sample Output 2:
There is 1 account and no account is modified
Sample Input 3:
2
team110 abcdefg222
team220 abcdefg333
Sample Output 3:
There are 2 accounts and no account is modified



#include<stdio.h>
#include<string.h>
#include<math.h>

int main(){
char Team[20],PIN[20],store[20][40];
int n,N,flag,i,j,k;
int len1,len2;

while(scanf("%d",&n)!=EOF){
N=0;
for(i=0;i<n;i++){
flag=0;
scanf("%s%s",&Team,&PIN);
len1=strlen(Team);
len2=strlen(PIN);
for(j=0;j<len2;j++){
if(PIN[j]=='0'){
PIN[j]='%';
flag=1;}
else if(PIN[j]=='1'){
PIN[k]='@';
flag=1;}
else if(PIN[j]=='o'){
PIN[k]='O';
flag=1;}
else if(PIN[j]=='l'){
PIN[j]='L';
flag=1;}
}
if(flag==1){
for(k=0;k<len1;k++) store[N][k]=Team[k];
store[N][k]=' ';
for(k=0;k<len2;k++) store[N][k+len1]=PIN[k];
store[N][len1+len2]='\n';
N++;
}
}
if(N==0)printf("There is %d account and no account is modified\n",n);
else {
printf("%d\n",N+1);
for(i=0;i<=N;i++){
for(j=0;j<len1+len2+1;j++){
printf("%c",store[i][j]);
}
printf("\n");
}
}
}
return 0;
}



[调试的时候有“Unhandled exception at 0x012038fd in 甲1035.exe: 0xC0000005: Access violation writing location 0xcce8c928.”,没有语法错误可是也不知道哪里错了,拜托大家看一下!!谢谢谢谢了!
...全文
113 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-05-24
  • 打赏
  • 举报
回复
关于自己是否适合编程的很简单的测试: 在报纸或杂志上随便找一段约1000字的文章,在Word中输入一遍。输完后再参考下面答案: A里面有10处以上文字或标点错误 B里面没有文字或标点错误并敢为此跟人打赌 C里面没有文字或标点错误并且字体和排版完全与原稿一致 D打印在半透明的纸上和原稿重叠在一起检查一模一样,且自我感觉很有成就感 A不适合编程(理由:打字准确度偏低、粗心大意) B初级程序员(理由:打字准确度很高、认真细致、自信、理解全角半角概念) C高级程序员(理由:在B的基础上理解字体和排版也是电脑打印的重要因素、但相比D还不够偏执、精益求精、结果可验证) D软件项目经理(理由:能针对项目给出令人信服的细致到极点的需求说明和典型测试用例。用户几乎挑不出毛病。专业!) 如果想从A变成B的话,到我的资源http://download.csdn.net/detail/zhao4zhong1/4084259里面下载“适合程序员的键盘练习”
小灸舞 版主 2016-05-24
  • 打赏
  • 举报
回复
else if(PIN[j]=='1')和else if(PIN[j]=='o')里 PIN[j]都写成PIN[k]了吧 最下面的else分支也不对吧?多循环了一次吧? 单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。

#include<stdio.h>
#include<string.h>
#include<math.h>
 
int main(){
    char Team[20],PIN[20],store[20][40];
    int n,N,flag,i,j,k;
    int len1,len2;
 
    while(scanf("%d",&n)!=EOF){
        N=0;
        for(i=0;i<n;i++){
            flag=0;
            scanf("%s%s",&Team,&PIN);
            len1=strlen(Team);
            len2=strlen(PIN);
            for(j=0;j<len2;j++){
                if(PIN[j]=='0'){
                    PIN[j]='%';
                    flag=1;}
                else if(PIN[j]=='1'){
                    PIN[j]='@';
                    flag=1;}
                else if(PIN[j]=='o'){
                    PIN[j]='O';
                    flag=1;}
                else if(PIN[j]=='l'){
                    PIN[j]='L';
                    flag=1;}
            }
            if(flag==1){
                for(k=0;k<len1;k++) store[N][k]=Team[k];
                store[N][k]=' ';
                for(k=0;k<len2;k++) store[N][k+len1]=PIN[k];
                store[N][len1+len2]='\n';
                N++;
            }
        }
        if(N==0)printf("There is %d account and no account is modified\n",n);
        else {
            printf("%d\n",N);
            for(i=0;i<N;i++){
                for(j=0;j<len1+len2+1;j++){
                    printf("%c",store[i][j]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}

70,024

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧