R11happy的博客

春风十里、五十里、一百里、体测一千米,木瓜炖雪梨、芝士玉米粒、鸡汁土豆泥,不如你,全都不如你~...

PAT甲级.1035. Password (20)

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 );
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/R11happy/article/details/52382617
个人分类: PAT甲级
上一篇PAT甲级.1005. Spell It Right (20)
下一篇PAT甲级.1077. Kuchiguse (20)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭