problemscpp
A collection of my answers to algorithm problems in c++.
函数
pat::b::b1067 命名空间参考

1067 试密码 更多...

函数

int main (istream &cin, ostream &cout)
 
 TEST (b1067, case1)
 
 TEST (b1067, case2)
 

详细描述

1067 试密码

函数说明

◆ main()

int pat::b::b1067::main ( istream &  cin,
ostream &  cout 
)

在文件 pat.cpp2303 行定义.

2303 {
2304 string pwd;
2305 int n;
2306 cin >> pwd >> n;
2307 int cnt = 0;
2308 char s[1024];
2309 cin.getline(s, 1024);
2310 while(true) {
2311 cin.getline(s, 1024);
2312 auto str = string(s);
2313 if(str == "#") {
2314 return 0;
2315 }
2316 if(cnt == n) {
2317 cout << "Account locked";
2318 return 0;
2319 }
2320 if(str != pwd) {
2321 cout << "Wrong password: " << str << endl;
2322 cnt++;
2323 if(cnt == n) {
2324 cout << "Account locked";
2325 return 0;
2326 }
2327 } else {
2328 cout << "Welcome in";
2329 return 0;
2330 }
2331 }
2332 }

被这些函数引用 TEST().

◆ TEST() [1/2]

pat::b::b1067::TEST ( b1067  ,
case1   
)

在文件 pat_test.cpp1022 行定义.

1022 {
1023 istringstream in("Correct%pw 3\n"
1024 "correct%pw\n"
1025 "Correct@PW\n"
1026 "whatisthepassword!\n"
1027 "Correct%pw\n"
1028 "#");
1029 auto out = ostringstream();
1030 main(in, out);
1031 const auto ans = out.str();
1032 ASSERT_EQ("Wrong password: correct%pw\n"
1033 "Wrong password: Correct@PW\n"
1034 "Wrong password: whatisthepassword!\n"
1035 "Account locked",
1036 out.str());
1037 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

pat::b::b1067::TEST ( b1067  ,
case2   
)

在文件 pat_test.cpp1039 行定义.

1039 {
1040 istringstream in("cool@gplt 3\n"
1041 "coolman@gplt\n"
1042 "coollady@gplt\n"
1043 "cool@gplt\n"
1044 "try again\n"
1045 "#");
1046 auto out = ostringstream();
1047 main(in, out);
1048 const auto ans = out.str();
1049 ASSERT_EQ("Wrong password: coolman@gplt\n"
1050 "Wrong password: coollady@gplt\n"
1051 "Welcome in",
1052 out.str());
1053 }

引用了 main().