/*學習事項
1.使用string時,千萬注意數字與符號的數字是不同的 eg. '0' != 0
2.用cout除錯其實很好用
*/
#include
using namespace std;
#include
int AlphabetToInt(char letter);
int main()
{
string ID;
while (cin>>ID)
{
int sum=0, ch_num=0;
//deal with alphabet
sum += ( AlphabetToInt(ID[0]) / 10 );
sum += ( AlphabetToInt(ID[0]) % 10 )*9;
//cout<<( AlphabetToInt(ID[0]) / 10 )<//cout<<( AlphabetToInt(ID[0]) % 10 )*9< //cout << (int)'1'<
for(int index=1,mul=8;mul>=1;index++,mul--)
{
sum += ( (ID[index]-(int)'0') * mul );
//cout<< ID[index] << " " << (ID[index]-(int)'0') << " " <//cout< }
//cout<sum += (ID[9]-'0'); //最後一位數 千萬要注意'8'跟數字8是不同的!!
//cout<//cout< cout<<( (sum%10==0)? "real":"fake" )< }
//system("pause");
return 0;
}
int AlphabetToInt (char letter)
{
int v[]=
{ 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21,
22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33};
int i = letter - 'A';
return v[i];
}
Sunday, August 7, 2011
a020. 身分證檢驗
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment