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

1031 查验身份证 更多...

函数

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

详细描述

1031 查验身份证

函数说明

◆ main()

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

在文件 pat.cpp1026 行定义.

1026 {
1027 int n;
1028 cin >> n;
1029 const char captcha[11] = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
1030 const int weight[17] = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
1031 bool flag = true;
1032 for(int i = 0; i < n; i++) {
1033 string str;
1034 cin >> str;
1035 int sum = 0;
1036 for(int j = 0; j < 17; j++) {
1037 sum += weight[j] * (str[j] - '0');
1038 }
1039 sum %= 11;
1040 if(str[17] != captcha[sum]) {
1041 cout << str << endl;
1042 flag = false;
1043 }
1044 }
1045 if(flag) {
1046 cout << "All passed";
1047 }
1048 return 0;
1049 }

被这些函数引用 TEST().

◆ TEST() [1/2]

pat::b::b1031::TEST ( b1032  ,
case1   
)

在文件 pat_test.cpp445 行定义.

445 {
446 istringstream in("4\n"
447 "320124198808240056\n"
448 "12010X198901011234\n"
449 "110108196711301866\n"
450 "37070419881216001X");
451 auto out = ostringstream();
452 main(in, out);
453 const auto ans = out.str();
454 ASSERT_EQ("12010X198901011234\n"
455 "110108196711301866\n"
456 "37070419881216001X\n",
457 out.str());
458 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().

◆ TEST() [2/2]

pat::b::b1031::TEST ( b1032  ,
case2   
)

在文件 pat_test.cpp460 行定义.

460 {
461 istringstream in("2\n"
462 "320124198808240056\n"
463 "110108196711301862");
464 auto out = ostringstream();
465 main(in, out);
466 const auto ans = out.str();
467 ASSERT_EQ("All passed",
468 out.str());
469 }

引用了 main().