1. 程式人生 > >1067 試密碼

1067 試密碼

clu main problems name -- std com != getc

題目鏈接: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 試密碼