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.

Input Specification:
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.

Output Specification:
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.

Sample Input 1:

3
Team000003 perfectpwd
Team000001 R1spOdfa

Sample Output 1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

Sample Input 2:

1
team110 abcdefg332

Sample Output 2:

There is 1 account and no account is modified

Sample Input 3:

2
team110 abcdefg222
team220 abcdefg333

Sample Output 3:

There are 2 accounts and no account is modified

之前的题解定义了结构体,较为复杂:

 #include<cstdio>
 #include<iostream>
 #include<cstring>
 using namespace std;

struct Users{
    char num[20];
    char pass[20];
    bool flag = false;
}user[1005];
int main()

  {
    int N;
    int sum=0;
    scanf("%d",&N);
    int i,j;
    for(i=0;i<N;i++)
    {
        scanf("%s %s",user[i].num,user[i].pass);
        for( j=0;j<strlen(user[i].pass);j++)
        {
            if(user[i].flag!=true)
            {
            if(user[i].pass[j]=='1') {user[i].pass[j]='@';user[i].flag=true;break;}
            if(user[i].pass[j]=='0') {user[i].pass[j]='%';user[i].flag=true;break;}
            if(user[i].pass[j]=='l') {user[i].pass[j]='L';user[i].flag=true;break;}
            if(user[i].pass[j]=='O') {user[i].pass[j]='o';user[i].flag=true;break;}

              }
            if(user[i].flag==true)
            {
                sum++;
                break;
            }

          }
      }

    if(sum)
    {
        printf("%d",sum);
        for(int i=0;i<N;i++)
        {
            if(user[i].flag==true)
            {
            printf("\n");
            printf("%s %s",user[i].num,user[i].pass);
              }

          }
      }
      else
      {
        if(N==1)
        {
            printf("There is 1 account and no account is modified");
          }
          else
          {
            printf("There are %d accounts and no account is modified",N);
          }
      }
   } 

更好的是:

#include <iostream>
#include <vector>
using namespace std;
int main() {
         int n;
         scanf("%d", &n);
         vector<string> v;
         for(int i = 0; i < n; i++) {
                 string name, s;
                 cin >> name >> s;
                 int len = s.length(), flag = 0;
                 for(int j = 0; j < len; j++) {
                         switch(s[j]) {
                                 case '1' : s[j] = '@'; flag = 1; break;
                                 case '0' : s[j] = '%'; flag = 1; break;
                                 case 'l' : s[j] = 'L'; flag = 1; break;
                                 case 'O' : s[j] = 'o'; flag = 1; break;
                         }
                  }
         if(flag) {
                 string temp = name + " " + s;
                 v.push_back(temp);
             }
         }
         int cnt = v.size();
         if(cnt != 0) {
                 printf("%d\n", cnt);
                 for(int i = 0; i < cnt; i++)
                 cout << v[i] << endl;
         }
        else if(n == 1) {
                 printf("There is 1 account and no account is modified");
         }
        else {
                 printf("There are %d accounts and no account is modified", n);
         }
             return 0;
}

使用C++里的vectorstring组合将题目解出,省去了使用结构体的麻烦

PAT甲级——1035 Password (20分)的更多相关文章

  1. PAT 甲级 1035 Password (20 分)(简单题)

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

  2. PAT Advanced 1035 Password (20 分)

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

  3. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  4. PAT 甲级 1035 Password (20 分)

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

  5. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  6. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  7. 【PAT甲级】1035 Password (20 分)

    题意: 输入一个正整数N(<=1000),接着输入N行数据,每行包括一个ID和一个密码,长度不超过10的字符串,如果有歧义字符就将其修改.输出修改过多少组密码并按输入顺序输出ID和修改后的密码, ...

  8. PAT (Advanced Level) Practice 1035 Password (20 分)

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

  9. 【PAT】1035. Password (20)

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

随机推荐

  1. 【LeetCode】电话号码的字母组合

    [问题]给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合. 给出数字到字母的映射如下(与电话按键相同).注意 1 不对应任何字母. 示例: 输入:" 输出:["ad ...

  2. JDBC批处理方法

    每次新建Connection的时候相当于建了一座桥,每次一辆车(PreparedStatement)运送货物(ResultSet)成本太高! 每次都建立网络连接的时间远远大于本地的时间,为了处理大量的 ...

  3. 第二章,C语言概述

    2.1 简单的C程序示例 #include <stdio.h> #include <stdlib.h> int main(void) { int num; num=; prin ...

  4. 一天一个设计模式——Bridge桥接模式

    一.概念准备 在理解桥接模式之前,先要理解面向对象程序设计中的两个概念: 类的功能层次结构:假设现在有一个类Something,这个类有一些成员属性和成员方法,但是现有的功能不能满足要求,因此我们想扩 ...

  5. SQL字符替换函数translater, replace

    translate() 函数原型是:translate(string, from, to) SELECT TRANSLATE('12345', '134', 'ax') 得到:a2x5 这个函数会把f ...

  6. k8s pod.yml解释

    apiVersion: v1kind: Podmetadata:  name: yueying  namespace: kube-public  labels:    name: testpodssp ...

  7. delphi save .dfm to .txt

    procedure TForm2.saveDfm; var inStream,outStream:TMemoryStream; begin inStream:=TMemoryStream.Create ...

  8. dirname() 函数返回路径中的目录部分。

    定义和用法 dirname() 函数返回路径中的目录部分. 语法 dirname(path) 参数 描述 path 必需.规定要检查的路径. 说明 path 参数是一个包含有指向一个文件的全路径的字符 ...

  9. winform显示、隐藏任务栏及开始菜单

    private const int SW_HIDE = 0; //隐藏 private const int SW_RESTORE = 9;//显示 /// <summary> /// 获取 ...

  10. 201712-2 游戏 Java

    思路: 第一感觉有点像约瑟夫环.想到用队列解决比较好理解 import java.util.LinkedList; import java.util.Queue; import java.util.S ...