#12052: C++ 參考解答


shawn2000100 (東華財金)

學校 : 國立東華大學
編號 : 57300
來源 : [27.53.168.5]
最後登入時間 :
2021-09-19 19:53:19
a054. 電話客服中心 -- 板橋高中教學題 | From: [134.208.255.201] | 發表日期 : 2017-05-21 15:12

#include<iostream>
#include<cstring>
using namespace std;

int main()
{
int city[26] = {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
};
char charCity[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z'
};
string input;
string output;
while ( cin >> input ) {
for ( int i = 0; i < input.length(); i++ )
input[i] -= '0';
int checkNumber = input[8];
int sum = 0;

for ( int i = 0; i < 26; i++ ) {
sum += ( ( ( city[i] % 10 ) * 9 ) + ( city[i] / 10 ) );

for ( int j = 0, k = 8; j < 8; j++, k-- )
sum += ( input[j] * k );

if ( ( sum + checkNumber) % 10 == 0 )
output += charCity[i];

sum = 0;
}
for ( int i = 0; i < output.length(); i++ )
cout << output[i];
cout << endl;
output.clear();
}
return 0;
}

 
ZeroJudge Forum