PAT 1067 乙等 (试密码) c++ 版本

来源:互联网 发布:加内特巅峰数据 编辑:程序博客网 时间:2024/06/15 07:42

此题比较简单,实现中有注释需注意的地方。

#include <iostream>#include <string>using namespace std;int main(){    string pwd; // 正确密码    int n; // 错误次数    cin >> pwd >> n;    string temp;    getline(cin, temp);   //消除cin 使用后的回车    string pwd1;   // 接受输入的密码    do{        getline(cin, pwd1);        n--;        if (pwd1 == "#")    //测试点2. 读到‘#’字符时结束输入            break;          if (n >= 0 && pwd1 == pwd){            cout << "Welcome in";            break;        }        else if (n > 0 && pwd1 != pwd){            cout << "Wrong password: " << pwd1 << endl;        }        if (n == 0 && pwd1 != pwd){            cout << "Wrong password: " << pwd1 << endl;            cout << "Account locked";            break;        }    } while (pwd1!="#");        return 0;}
0 0
原创粉丝点击