首页 > 其他 > 详细

PAT-字符串处理-A 1035 Password (20分)

时间:2020-03-15 00:11:58      阅读:53      评论:0      收藏:0      [点我收藏+]

题目:

技术分享图片

思路:

  将用户名和密码一起读入到字符串,然后对字符串进行遍历,依据题目对字符串进行改变,将改变的字符串存储到向量中,最后依据向量的大小分别依据题意进行输出

注意点:

  当没有需要修改二点密码时,需注意带到输出语句的单复数

代码:

技术分享图片
 1 #include<iostream>
 2 #include<vector>
 3 #include<string>
 4 #include<unordered_map>
 5 #include<algorithm>
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int num, count = 0;
11     vector<string> res;
12 
13     scanf("%d", &num);
14 
15     for (int i = 0;i < num;i++)
16     {
17         //读入存储输入数据
18         string temp, name, password;
19         cin >> name >> password;
20         temp = name +   + password;
21 
22         //标记语是否需修改
23         bool flag = true;
24         //遍历字符串,对需要修改的进行修改
25         for(int j=temp.size()-1;i>=0;j--)
26         {
27             switch (temp[j])
28             {
29             case 1:
30                 temp[j] = @;
31                 flag = false;
32                 break;
33             case 0:
34                 temp[j] = %;
35                 flag = false;
36                 break;
37             case l:
38                 temp[j] = L;
39                 flag = false;
40                 break;
41             case O:
42                 temp[j] = o;
43                 flag = false;
44                 break;
45             }
46 
47             //在空格处中断,不进行到用户名
48             if (temp[j] ==  )break;
49         }
50 
51         //添加修改的字符串
52         if (!flag)res.push_back(temp);
53     }
54 
55     //依据向量的大小分别进行输出1
56     if (!res.size())
57     {
58         //注意输出语句额单复数
59         if (num > 1)printf("There are %d accounts and no account is modified",num);
60         else printf("There is 1 account and no account is modified");
61     }
62     else
63     {
64         //遍历输出
65         cout << res.size() << endl;
66         for (int i = 0;i < res.size();i++)
67         {
68             cout << res[i] << endl;
69         }
70     }
71     return 0;
72 }
View Code

 

PAT-字符串处理-A 1035 Password (20分)

原文:https://www.cnblogs.com/fangzhiyou/p/12495231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!