PAT甲级.1035. Password (20)

原创 2016年08月31日 10:41:18

1035. Password (20)


题目

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.

输入格式

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.

输出格式

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.

输入样例 1

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

输出样例1

2
Team000002 RLsp%dfa
Team000001 R@spodfa

输入样例2

1
team110 abcdefg332

输出样例2

There is 1 account and no account is modified

输入样例3

2
team110 abcdefg222
team220 abcdefg333

输出样例3

There are 2 accounts and no account is modified

PAT链接


思路:

1.struct结构存信息

const int Max = 1000;
struct account
{
    char id[15];
    char password[15];
}modify[Max+10],tmp;

2.读取信息,并做对应修改


代码:

/**
* @tag     PAT_A_1035
* @authors R11happy (xushuai100@126.com)
* @date    2016-8-28 22:55-23:20
* @version 1.0
* @Language C++
* @Ranking  360/2499
* @function null
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>

const int Max = 1000;
struct account
{
    char id[15];
    char password[15];
}modify[Max+10],tmp;

int main(int argc, char const *argv[])
{
    int N;
    int m_cnt = 0;
    scanf("%d", &N);
    for(int i = 0; i < N; i++)
    {
        scanf("%s %s", tmp.id, tmp.password);
        int flag = 0;
        for(int j = 0; j<strlen(tmp.password); j++)
        {
            if(tmp.password[j] == '1')  {tmp.password[j] = '@';flag = 1;}
            else if(tmp.password[j] == '0') {tmp.password[j] = '%';flag = 1;}
            else if(tmp.password[j] == 'l') {tmp.password[j] = 'L';flag = 1;}
            else if(tmp.password[j] == 'O') {tmp.password[j] = 'o';flag = 1;}
        }
        if(flag)
        {
            modify[m_cnt++] = tmp;  //开始写成modify[i] = tmp; m_cnt++;  不合适
        }
    }
    if(m_cnt)
    {
        printf("%d\n",m_cnt );
        for(int i = 0; i < m_cnt; i++)  printf("%s %s\n",modify[i].id,modify[i].password );
    }
    //注意,N=1和N>2不一样
    else if(N == 1) printf("There is 1 account and no account is modified\n");
    else    printf("There are %d accounts and no account is modified\n",N );
    return 0;
}

收获:

1.读取字符串中不含空格,用scanf
读取字符串中含空格,用gets
2.注意输出格式,本题N==1和N>2的输出格式不同

else if(N == 1) printf("There is 1 account and no account is modified\n");
    else    printf("There are %d accounts and no account is modified\n",N );
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

PAT(甲级)1035. Password (20)

题目:https://www.patest.cn/contests/pat-a-practise/1035 代码:#include #include #include #include using ...

1035. Password (20)-PAT甲级真题

1035. Password (20) To prepare for PAT, the judge sometimes has to generate random passwords fo...

浙江大学PAT_甲级_1035. Password (20)

C++

PAT-A 1035. Password (20)

PAT-A 1035. Password (20)

1035. Password (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息1035. Password (20)时间限制400 ms 内存限制65536 kB 代码长度限制16000 BTo prepare for PAT, the judge sometime...

PAT A1035. Password (20)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

PAT A 1035. Password (20)

题目 To prepare for PAT, the judge sometimes has to generate random passwords for the users.  The pro...

PAT 1035. Password (20)

1035. Password (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B ...

【PAT】1035. Password (20)

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1035 分析:简单题。直接搜索,然后替换,不会超时,但是应该有更好的办法。 题目描述: ...

PAT (Advanced Level) Practise 1035 Password (20)

1035. Password (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)