#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char q[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'};
int qi[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 a[9];
while(cin>>a){
int ai[9],to=0,to1=0,a1,a2;
for(int r1=0;r1<9;r1++){
ai[r1]=int(a[r1])-48;
// cout<<ai[r1];
}
for(int r1=0;r1<8;r1++){
to=to+ai[r1]*(8-r1);
}
to=to+ai[8];
for(int r1=0;r1<26;r1++){
to1=to;
a1=qi[r1]/10;
a2=qi[r1]%10;
to1=to1+a1+(a2*9);
if(to1%10==0) cout<<q[r1];
}
cout<<endl;
}
return 0;
}
您的答案為: MW 正確答案為: AMW
但我自己測試多筆資料 都有正常跑出AMW
可是在執行上卻都WA (line:9)
懇請各位大大幫忙。
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char q[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'};
int qi[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 a[9];
while(cin>>a){
int ai[9],to=0,to1=0,a1,a2;
for(int r1=0;r1<9;r1++){
ai[r1]=int(a[r1])-48;
// cout<<ai[r1];
}
for(int r1=0;r1<8;r1++){
to=to+ai[r1]*(8-r1);
}
to=to+ai[8];
for(int r1=0;r1<26;r1++){
to1=to;
a1=qi[r1]/10;
a2=qi[r1]%10;
to1=to1+a1+(a2*9);
if(to1%10==0) cout<<q[r1];
}
cout<<endl;
}
return 0;
}
您的答案為: MW 正確答案為: AMW
但我自己測試多筆資料 都有正常跑出AMW
可是在執行上卻都WA (line:9)
懇請各位大大幫忙。
試試將char a[9]改大一點
#include
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
char q[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'};
int qi[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 a[9];
while(cin>>a){
int ai[9],to=0,to1=0,a1,a2;
for(int r1=0;r1<9;r1++){
ai[r1]=int(a[r1])-48;
// cout<<ai[r1];
}
for(int r1=0;r1<8;r1++){
to=to+ai[r1]*(8-r1);
}
to=to+ai[8];
for(int r1=0;r1<26;r1++){
to1=to;
a1=qi[r1]/10;
a2=qi[r1]%10;
to1=to1+a1+(a2*9);
if(to1%10==0) cout<<q[r1];
}
cout<<endl;
}
return 0;
}
您的答案為: MW 正確答案為: AMW
但我自己測試多筆資料 都有正常跑出AMW
可是在執行上卻都WA (line:9)
懇請各位大大幫忙。
試試將char a[9]改大一點
改大就AC了也
小弟不才,請問大大為什麼改大就可以了呢?
char [9] 不是0-8 剛好九個與身分證字號的數字九個相符,小弟不太明白為什麼需要改大,再麻煩大大說明,感謝。