PAT-乙-1067 1067 試密碼 (20 分)
阿新 • • 發佈:2018-11-03
程式碼
#include <iostream> using namespace std; int main() { string s; int n; cin>>s>>n; string t; getline(cin, t); int tryNumber = 0; getline(cin, t); while(t.compare("#")){ if(t.compare(s)){ tryNumber++; if(tryNumber<n){ cout<<"Wrong password: "<<t<<endl; getline(cin, t); } else if(tryNumber==n){ cout<<"Wrong password: "<<t<<endl; cout<<"Account locked"<<endl; break; } } else{ cout<<"Welcome in"<<endl; break; } } return 0; }
註解
1、模擬題。按照題目意思進行模擬,注意控制迴圈即可。