zoj2514 Generate Passwords

本文探讨了在编程竞赛和考试中生成并验证密码时遇到的混淆问题,通过替换特定字符来解决1与l,0与O之间的混淆,并提供了解决方案及代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Time Limit: 2000MS Memory Limit: 65536KB 64bit IO Format: %lld & %llu

 Status

Description

To prepare for programming contests or coding examinations, 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

There are multiple test cases. 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. A test case with N = 0 denotes the end of input. This test case is not to be processed.

Output

For each 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 "No account is modified."

Sample Input:
2
Team000001 R1spOdfa
Team000002 Rlsp0dfa
1
team110 abcdefg332
0
Sample Output:
2
Team000001 R@spodfa
Team000002 RLsp%dfa
No account is modified.

Source

CYJJ's Funny Contest #1, Killing in Seconds
 
 
 
分析:
坑题。注意用户名是不需要改的,只改密码。另外输出也是个坑,调试了很久。
总之认真读题,仔细分析就行。难度在于编程,不涉及算法。
ac代码:
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char c1[1001][11],c2[1001][11];
int main()
{
    int n,i,j,k;
    int len1,len2;
    int count;
    bool flag[1001];
    //bool flag3[4],flag4[4]
    while(scanf("%d",&n)&&n)
    {
       count=0;
       //flag2=false;
       //flag3={false};
       //flag4={false};
        for(i=0;i<n;i++)
        {
            //scanf("%s%s",c1[i],c2[i]);
            cin>>c1[i]>>c2[i];
        }
        //flag={false};
        /*这种写法本地编译没问题,但是提交vjudge,则提示
        extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default],
        意思是编译器告诉你延迟初始化话仅仅在C++0x标准或gnu++ox标准中使用,如果你是要这么做而漏加了选项,那么假如提示的编译选项就可以解决。
        简单讲就是编译器要求数组单个赋值,不能一次性赋值。*/
        for(i=0;i<n;i++)//
        flag[i]=false;
        for(i=0;i<n;i++)
        {
            //len1=strlen(c1[i]);
            len2=strlen(c2[i]);
           /* for(j=0;j<len1;j++)
            {
                if(c1[i][j]=='1')
                {
                    c1[i][j]='@';
                    flag[i]=true;
                }
                else if(c1[i][j]=='0')
                {
                    c1[i][j]='%';
                    flag[i]=true;
                }
                else if(c1[i][j]=='l')
                {
                    c1[i][j]='L';
                    flag[i]=true;
                }
                else if(c1[i][j]=='O')
                {
                     c1[i][j]='o';
                     flag[i]=true;
                }
            }*/
            for(j=0;j<len2;j++)
            {
                if(c2[i][j]=='1')
                {
                    c2[i][j]='@';
                    flag[i]=true;
                }
                else if(c2[i][j]=='0')
                {
                    c2[i][j]='%';
                    flag[i]=true;
                }
                else if(c2[i][j]=='l')
                {
                    c2[i][j]='L';
                    flag[i]=true;
                }
                else if(c2[i][j]=='O')
                {
                    c2[i][j]='o';
                    flag[i]=true;
                }
            }
           if(flag[i]) count++;
        }
        if(!count) printf("No account is modified.\n");
        else
        {
            printf("%d\n",count);
            for(i=0;i<n;i++)
            {
                if(flag[i])
                cout<<c1[i]<<" "<<c2[i]<<endl;
            }
        }
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值