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

1081 检查密码 更多...

函数

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

详细描述

1081 检查密码

函数说明

◆ main()

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

在文件 pat.cpp2851 行定义.

2851 {
2852 int n;
2853 cin >> n;
2854 char str[1024];
2855 cin.getline(str, 1024);
2856 while(n-- != 0) {
2857 cin.getline(str, 1024);
2858 auto password = string(str);
2859 bool alpha = false;
2860 bool digit = false;
2861 bool ok = true;
2862 if(password.length() < 6) {
2863 cout << "Your password is tai duan le." << endl;
2864 } else {
2865 for(const char ch: password) {
2866 if(isdigit(ch) != 0) {
2867 digit = true;
2868 } else if(isalpha(ch) != 0) {
2869 alpha = true;
2870 } else if(ch != '.') {
2871 ok = false;
2872 cout << "Your password is tai luan le." << endl;
2873 break;
2874 }
2875 }
2876 if(!ok) {
2877 continue;
2878 }
2879 if(alpha && !digit) {
2880 cout << "Your password needs shu zi." << endl;
2881 } else if(!alpha && digit) {
2882 cout << "Your password needs zi mu." << endl;
2883 } else if(alpha && digit) {
2884 cout << "Your password is wan mei." << endl;
2885 } else {
2886 return 1;
2887 }
2888 }
2889 }
2890 return 0;
2891 }

被这些函数引用 TEST().

◆ TEST()

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

在文件 pat_test.cpp1411 行定义.

1411 {
1412 istringstream in("5\n"
1413 "123s\n"
1414 "zheshi.wodepw\n"
1415 "1234.5678\n"
1416 "WanMei23333\n"
1417 "pass*word.6");
1418 auto out = ostringstream();
1419 main(in, out);
1420 const auto ans = out.str();
1421 ASSERT_EQ("Your password is tai duan le.\n"
1422 "Your password needs shu zi.\n"
1423 "Your password needs zi mu.\n"
1424 "Your password is wan mei.\n"
1425 "Your password is tai luan le.\n",
1426 out.str());
1427 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().