码迷,mamicode.com
首页 > 其他好文 > 详细

1067 试密码

时间:2018-11-25 01:20:48      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:else   getline   tps   line   main   str   std   getch   应该   

题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805266007048192

题解:

 1 //本题有一个坑需要注意:错误密码可以包含空格等,所以应该改用getline而不是cin进行输入
 2 #include<iostream>
 3 #include<string>
 4 #include<cstdio>
 5 using namespace std;
 6 
 7 int main() {
 8     string password, str;
 9     int n;
10     cin >> password >> n;
11     getchar();
12     while (true) {
13         getline(cin, str);
14         if (str == "#") break;
15         if (str != password) {
16             cout << "Wrong password: " << str << endl;
17             n--;
18         }
19         else {
20             cout << "Welcome in" << endl;
21             break;
22         }
23         if (n == 0) {
24             cout << "Account locked" << endl;
25             break;
26         }
27     }
28     return 0;
29 }

 

1067 试密码

标签:else   getline   tps   line   main   str   std   getch   应该   

原文地址:https://www.cnblogs.com/Gzu_zb/p/10014153.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!