【第22期】观点:IT 行业加班,到底有没有价值?

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)

#include #include #include using namespace std; typedef struct Acc { string name; string ...

PAT1035 Password

Sample Input 1: 3 Team000002 Rlsp0dfa Team000003 perfectpwd Team000001 R1spOdfa Sample Output 1: 2 Team000002 RLsp%dfa Team000001 R@spodfa ...

程序员升职加薪指南!还缺一个“证”!

CSDN出品,立即查看!

1035. Password (20)PAT 甲级

传送门#include #include using namespace std;struct people{ string name; string passwd; bool...
  • SY_Yu
  • SY_Yu
  • 2017-01-17 22:32
  • 52

pat 1019. General Palindromic Number (20)

链接:http://pat.zju.edu.cn/contests/pat-a-practise/1019   题意:给定一个十进制数和一个进制,判断该数字在该进制下是否为回文。   分析:简单的数字进制处理。  </

pat 1011. World Cup Betting (20)

链接:http://pat.zju.edu.cn/contests/pat-a-practise/1011   题意:给定数据,找到每行的最大值根据公式计算结果。   分析:简单模拟题目。   <pre na
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

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