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.”,没有语法错误可是也不知道哪里错了,拜托大家看一下!!谢谢谢谢了!
...全文
98 2 打赏 收藏 转发到动态 举报
写回复
用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;
}
Re:CCNA_CCNP 思科网络认证 PAT NAT 端口或地址转换 与端口映射======================# 本章课程大纲        公网地址和私网地址        NAT应用场景        静态NAT  :static  地址转换        动态NAT  :dynamic地址转换        PAT        :端口地址转换        端口映射 :port map        在Windows上同时实现的NAT和端口映射 # 私网地址三类 A类:10.0.0.0                                255.0.0.0(1网段) B类:172.16.0.0 -172.31.0.0         255.255.0.0(16网段) C类:192.168.0.0-192.168.255.0  255.255.255.0(255网段) # NAT 的使用场景        NAT的最初的目的是允许把私有IP地址映射到公网地址,以减缓IP地址空间的消耗。        当一个组织更换它的互联网服务提供商ISP,但不想更改内网配置方案时,NAT同样很有用途。        以下是适于使用NAT的多种情况:         企业内网接入Internet节省公网地址         单向访问         大方向:内网访问互联网(互联网上主机不能够访问内网主机)         小方向:同单位实现两个网段之间单向访问(涉密部门能够访问其他部门,反之不可)         增加一个网段          避免在主干路由器增加到这个网段的路由         在Windows上实现的NAT和端口映射 # 网络地址转换的类型        下面介绍一下NAT的三种类型。         静态NAT 是为了在私网地址和公网地址间,允许一对一映射而设计的。         或者IPv4和IPv6之间的转换(典型)         不节省公网地址,故公网地址的利用效率不高,         无任何安全性,外网可以通过公网地址直接攻击内网主机,好像只增加路由器的工作         适用场景类似代理,可以较方便的更换主机,而无需修改路由器的配置         故应用不够广泛...         动态NAT 可以实现映射一个未注册 IP地址到注册IP地址池中的一个注册IP地址。         多对一,或多对多         比较PAT优势:避免被误认为攻击而被封ip地址         不太节省地址,应用不广泛         复用是最流行的NAT配置类型,也被称为端口地址映射(PAT)。         通过使用PAT,可实现上千个用户仅通过一个真实的全球 IP地址连接到Internet。         缺点:增加延迟,消耗路由器性能 # 端口映射(port mapping) 允许Internet上的计算机通过企业路由器的公网IP地址访问到内网的服务器------------------------------------------------         

69,371

社区成员

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

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