Home > Back-end >  C language test id correcting code
C language test id correcting code

Time:10-10

Don't know where I went wrong
#include
Void exam (long long, int)
{
for(i=0; i<18; I++)
{
Arr=[i++] ID % 10;
ID=ID/10;
}
for(i=0; i<17. I++)
* a sum +=arr [I] [I];
The sum %=11;
Temp=b (sum) - '0';
If (temp!=arr [17])
flag=0;

}
Int main ()
{
Long long ID;
Int n, I, flag=1, arr [18].
The scanf (" % d ", & amp; N);
Int sum=0, a []={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
Char [] b={' 1 ', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2'};
for(i=1; i<=n; I++)
{
The scanf (" % LLD, & amp; ID);
Exam (long long ID, int I);
}
If (flag)
Printf (" All passed ");
return 0;
}

CodePudding user response:

You eat all the exam code go back inside the main again

Then the following two i++ can keep only one
for(i=0; i<18; i++
{
Arr [ i++ ]=ID % 10;
ID=ID/10;
}

CodePudding user response:

Also, the id number, if its tail is X, how are you this the scanf can't read characters in X
With a string as an input type, read in transformation

CodePudding user response:

People think that your idea is some of the problems, the last may be X, longlong cannot save
 # include 
#include
7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 int dis []={};
M char []={' 1 ', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
Char mp [100] [19].
Int main () {
Int n, num=0, I, j, k, ans=0;
Char id [19];
The scanf (" % d ", & amp; N);
for(i=0; iInt sum=0;
The scanf (" % s ", id);
for(j=0; j<17. J++) {
The sum +=(id [j] - '0') * dis [j];
}
The sum %=11;
If (m==id [17] [sum]) {
num++;
}
The else {
Strcpy (mp [ans++], id);
}
}
If (num==n) {
Printf (" All passed \ n ");
}
The else {
for(i=0; iPuts (mp) [I];
}
}
return 0;
}

CodePudding user response:

Can be simple:
 
#include

Int main ()
{
Const char v []={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
10 x98765432 const char * m="";

Char s [19];
Int n, I, c, x, p=0;

The scanf (" % d ", & amp; N);
While (n -)
{
The scanf (" % s ", s);
For (I=c=0; X=s [I] - 48, I & lt; 17. I++)
X & gt;=0 & amp; & X & lt; 10? C +=x * v [I] : I=19;
19 I==| | s [17]! M=[11] c %? P=puts (s) : 0;
}
if (! P) puts (" All passed ");

return 0;
}

CodePudding user response:

The original poster as integer arithmetic have one more question
for(i=0; i<18; I++)
{
Arr=[I] ID % 10;
ID=ID/10;
}
Here to get the number from low to high, arr [0] is the id of the 18th, arr [17] is one of the first
And the order of the multiplication of the array and him and he was just the opposite, from high to low order
So the back of the
for(i=0; i<17. I++)
* a sum +=arr [I] [I];
This is wrong,

With the LLD integer can be solved, but there are different methods

#include
#include

//id is 17 digits, ch is the most a checksum characters
//if the legitimate returns 0, wrong number return 1
Int exam (long long id, char ch)
{
Int sum=0;
Int arr [18].
7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 int a []={};
Char [] b={' 1 ', '0', 'x', '9', '8', '7', '6', '5', '4', '3', '2'};
Int I;
Long long ID=ID;
for(i=0; i<17. I++)
{
Arr=[I] ID % 10;
ID=ID/10;
}
for(i=0; i<17. I++)
The sum +=arr [16 - I] * a, [I].
The sum %=11;
Char temp=b (sum);
If (temp!=ch) {
Printf (" % % LLD % c: c \ n ", id, ch, temp);
return 1;
} the else
return 0;

}
Int main ()
{
Long long ID;
Int n, I, flag=0;
The scanf (" % d ", & amp; N);
for(i=1; i<=n; I++)
{
char ch;
//specified integer digits, the last one as a character input
While (2! 17 LLD %=the scanf (" % c ", & amp; ID, & amp; Ch)) {
The fflush (stdin);
Printf (" input error \ n \
Id number must be 18, only the last one can be a letter and can only be x!!!! \ n \
Please input again: \ n ");
}
Flag +=exam (ID, ch);
}
If (0==flag)
Printf (" All passed ");
return 0;
}
  • Related