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 );
版权声明:本文为博主原创文章,未经博主允许不得转载。

1058. 选择题(20)-PAT乙级真题

1058. 选择题(20) 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。 输入格式: 输入在第一行给出两个正整数N( 输出格式: 按照输入的顺序...
  • liuchuo
  • liuchuo
  • 2016年09月12日 09:07
  • 1536

PAT程序设计练习——甲级1002(两个多项式的解析与合并)

PAT程序设计能力测试 题目原文链接:点击打开链接 翻译题目要求: 程序输入为两行:均为一个多项式,按 K N1 An1 N2 An2 ......Nk Ank,K代表的是多项式的非零项数,范围闭区...
  • xexiyong
  • xexiyong
  • 2015年12月14日 13:18
  • 1068

PAT 1003. Emergency (25) (求两点间最短路的条数)

1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 ...
  • IAccepted
  • IAccepted
  • 2014年03月18日 12:19
  • 7729

PAT(甲级)1035. Password (20)

题目:https://www.patest.cn/contests/pat-a-practise/1035 代码:#include #include #include #include using ...
  • u012792707
  • u012792707
  • 2017年01月22日 19:27
  • 66

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

1035. Password (20) To prepare for PAT, the judge sometimes has to generate random passwords fo...
  • liuchuo
  • liuchuo
  • 2016年08月04日 18:28
  • 139

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

C++
  • pythontojava
  • pythontojava
  • 2015年06月16日 13:40
  • 500

PAT-A 1035. Password (20)

PAT-A 1035. Password (20)
  • Daniel960601
  • Daniel960601
  • 2017年02月23日 09:46
  • 133

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

题目信息1035. Password (20)时间限制400 ms 内存限制65536 kB 代码长度限制16000 BTo prepare for PAT, the judge sometime...
  • xianyun2009
  • xianyun2009
  • 2015年12月04日 16:44
  • 659

PAT A1035. Password (20)

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...
  • jolivan
  • jolivan
  • 2017年02月07日 17:47
  • 89

PAT A 1035. Password (20)

题目 To prepare for PAT, the judge sometimes has to generate random passwords for the users.  The pro...
  • xyzchenzd
  • xyzchenzd
  • 2014年05月15日 12:57
  • 374
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:PAT甲级.1035. Password (20)
举报原因:
原因补充:

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