Home > Back-end >  Check the problem of the id card. The PTA L1-016
Check the problem of the id card. The PTA L1-016

Time:11-01

write for the first time on this problem is a freshman just learning c + +, found that don't always have a testing point the code below
 # include 
using namespace std;
Struct Inf//declare a structure array
{
Char cid [19].
Int id [18];
Int amn.
Int flag=1;
} num [101].
Int main () {
Char box [11]={' 1 ', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
Int n, flag2=1;
Cin & gt;> n;
for (int i=0; i {
for (int j=0; J & lt; 18; J++)
{
Cin & gt;> Num [I]. Cid [j];
If (num [I]. Cid [j]=='0')
{
Num [I]. Id [j]=0;
}
Else if (num [I]. Cid [j]=='1')
{
Num [I]. Id [j]=1;
}
Else if (num [I]. Cid [j]=='2')
{
Num [I]. Id [j]=2;
}
Else if (num [I]. Cid [j]=='3')
{
Num [I]. Id [j]=3;
}
Else if (num [I]. Cid [j]=='4')
{
Num [I]. Id [j]=4;
}
Else if (num [I]. Cid [j]=='5')
{
Num [I]. Id [j]=5;
}
Else if (num [I]. Cid [j]=='6')
{
Num [I]. Id [j]=6;
}
Else if (num [I]. Cid [j]=='7')
{
Num [I]. Id [j]=7;
}
Else if (num [I]. Cid [j]=='8')
{
Num [I]. Id [j]=8;
}
Else if (num [I]. Cid [j]=='9')
{
Num [I]. Id [j]=9;
}
Else if (num [I]. Cid [17]=='X')
{
Num [I]. Id [j]=10;
}
}
}
for (int i=0; i {
Num [I]. Amn=((num [I] id [0]) * 7 + (num [I] id [1]) * 9 + (num [I] id [2]) * 10 +
(num [I] id [3]) * 5 + (num [I] id [4]) * 8 + (num [I] id [5]) * 4 +
(num [I] id [6]) * 2 + (num [I] id [7]) * 1 + (num [I] id [8]) * 6 +
(num [I] id [9]) * 3 + (num [I] id [10]) * 7 + (num [I] id [11]) * 9 +
(num [I] id [12]) * 10 + (num [I] id [13]) * 5 + (num [I] id [14]) * 8 +
(num [I] id [15]) * 4 + (num [I] id [16]) * 2) % 11;
}
for (int i=0; i {
for (int j=0; J & lt; 17. J++)
{
The switch (num [I] id [j])
{
Case 0: break;
Case 1: break;
Case 2: break;
Case 3: break;
Case 4: break;
Case 5: break;
Case 6: break;
Case 7: break;
Case 8: break;
Case 9: break;
Default: {the for (int o=0; O & lt; 18; O++) 17 before//will not output digital ID of the
{
Cout & lt; }
Cout & lt; Num [I] flag=0;
Flag2=0;
break; }
}
}
If ((box [num [I] amn]! Num=[I]. Cid [17]) & amp; & Num [I] flag!=0)
{
for (int j=0; J & lt; 18; J++)
{
Cout & lt; Flag2=0;
}
Cout & lt; }
}
If (flag2==1)
{
Cout & lt; <"All passed";
}
return 0;
}

was bloated,,,,
Now a sophomore practice topic to write again after the found 15 points, now code below
 # include 
using namespace std;
Int main () {
Int n, flag2=0;
Int quan [17]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
Char code [11]={' 1 ', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
String id;
Cin & gt;> n;
getchar();
for (int i=0; i {
Int flag1=0, z=0;//xianhou
Getline (cin, id);
for (int j=0; J & lt; 17.//panduanqian17wei j++)
{
If (id [j] <'0' | | id [j] & gt; '9')
{
Cout & lt; Flag1=1;
Flag2=1;
}
}
If (flag1==0)
{
for (int j=0; J & lt; 17. J++)
{
Z +=(id [j] - '0') * quan [j];
}
Z=z % 11;
If (id [17]!=code [z])
{
Cout & lt; Flag2=1;
}
}
}
If (flag2==0)
{
Cout & lt; <"All passed";
}
return 0;
}

But as written before the code is so bad, cause he has been to find out why not 15 points, so in the BBS for help you,
  • Related