Created
December 18, 2010 09:32
-
-
Save johnhmj/746346 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
real | |
real | |
real | |
real | |
fake | |
fake | |
real | |
real | |
real | |
real | |
real | |
real | |
real | |
real | |
fake | |
fake | |
real | |
fake | |
fake | |
real | |
real | |
fake | |
fake | |
fake | |
fake | |
fake | |
fake | |
fake | |
real | |
fake | |
fake | |
fake | |
real | |
fake | |
fake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Integrated Development Environment | |
// Visual C++ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "twidc.h" | |
// | |
int main(int argc, char* argv[]) | |
{ | |
Id id; | |
char IptBfr[1024] = ""; | |
//printf("Input an ID: "), scanf("%s", IptBfr); | |
// | |
// Cmdline: twidc.exe < TestData.txt | |
while ( scanf("%s", IptBfr) != EOF ) | |
{ | |
if ( SetTwId(&id, IptBfr) == 1 ) | |
{ | |
printf("%s\n", ((IsTwId(&id) == 1)?"real":"fake")); | |
} | |
else | |
{ | |
printf("failed\n"); | |
} | |
} | |
// | |
//system("PAUSE"); | |
return (0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
W211190876 | |
A164416414 | |
P198743888 | |
H189799297 | |
G502860248 | |
D598407636 | |
Z224235385 | |
D185871016 | |
S257694567 | |
G253102416 | |
X257101944 | |
X217849232 | |
X219760083 | |
K106642271 | |
B740948824 | |
F517115276 | |
B423221685 | |
H618927954 | |
H427793198 | |
G509006138 | |
D133604236 | |
J344606618 | |
E963788291 | |
B542097372 | |
G016575412 | |
D123341138 | |
A014607177 | |
H733599818 | |
X278114745 | |
C660380125 | |
A947835120 | |
B640618984 | |
Z283280955 | |
B439880877 | |
I383710734 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "twidc.h" | |
// | |
Local LocalTable[] = | |
{ | |
{'A', 10}, {'B', 11}, {'C', 12}, {'D', 13}, {'E', 14}, | |
{'F', 15}, {'G', 16}, {'H', 17}, {'I', 34}, {'J', 18}, | |
{'K', 19}, {'L', 20}, {'M', 21}, {'N', 22}, {'O', 35}, | |
{'P', 23}, {'Q', 24}, {'R', 25}, {'S', 26}, {'T', 27}, | |
{'U', 28}, {'V', 29}, {'W', 32}, {'X', 30}, {'Y', 31}, | |
{'Z', 33} | |
}; | |
int LocalLength = (int)(sizeof(LocalTable) / sizeof(LocalTable[0])); | |
// | |
int SetTwId(Id* id, const char* idstr) | |
{ | |
unsigned int len = 0; | |
int i = 0; | |
for (; idstr[len] != (char)NULL; len ++); | |
if ( len != IDSIZE ) | |
{ | |
return (0); | |
} | |
memset(id, 0, sizeof(Id)); | |
id->m_uppercase = idstr[0]; | |
// Return to uppercase | |
for (; i < LocalLength; i ++) | |
{ | |
if ( id->m_uppercase == ('a' + i) ) | |
{ | |
id->m_uppercase = ('A' + i); | |
break; | |
} | |
} | |
memcpy(id->m_number, (idstr + 1), (IDSIZE - 1)); | |
return (1); | |
} | |
int IsTwId(Id* id) | |
{ | |
int nRet = 0; | |
int i = 0, NumberLength = 9, nValue = 0, nParam = 0; | |
for (; i < LocalLength; i ++) | |
{ | |
if ( id->m_uppercase == LocalTable[i].m_code ) | |
{ | |
nValue += (LocalTable[i].m_value / 10); | |
nValue += ((LocalTable[i].m_value % 10) * 9); | |
break; | |
} | |
} | |
for (i = 0; i < NumberLength; i ++) | |
{ | |
nParam = (NumberLength - i - 1); | |
if ( nParam == 0 ) | |
{ | |
nParam = 1; | |
} | |
nValue += ((id->m_number[i] - '0') * nParam); | |
} | |
if ( (nValue % 10) == 0 ) | |
{ | |
nRet = 1; | |
} | |
return nRet; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _TWIDC_H_ | |
#define _TWIDC_H_ | |
#include <stdio.h> | |
#include <memory.h> | |
// | |
#define IDSIZE 10 | |
// | |
struct SLocal | |
{ | |
char m_code; | |
int m_value; | |
}; | |
typedef struct SLocal Local; | |
// | |
struct SIdentification | |
{ | |
// Uppercase | |
char m_uppercase; | |
// Number String | |
char m_number[IDSIZE]; | |
}; | |
typedef struct SIdentification Id; | |
// | |
// Set ID string to struct Id | |
// Return 1 is true; Return 0 is false | |
int SetTwId(Id* id, const char* idstr); | |
// | |
// Return 1 is true; Return 0 is false | |
int IsTwId(Id* id); | |
// | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment