#20577: 請問大大們~~TLE的部分可不可以給點提示~


twm0970420996@gmail.com (小胖胖胖)

學校 : 不指定學校
編號 : 94884
來源 : [122.116.200.57]
最後登入時間 :
2020-07-13 23:16:38
a159. 11743 - Credit Check -- UVa11743 | From: [117.19.145.174] | 發表日期 : 2020-02-09 16:30

#include <iostream>

using namespace std;
int mul(int);

string str = "";
char cre[20] = {};
int credit[20] = {};

int main(){
int T = 0 ;
cin >> T;
getline(cin,str);
for(int N = 0 ; N < T ; N++){
getline(cin,str);
for(int i = 18 ; i >= 0 ; i--){
cre[18-i] = str[i];
}

for(int i = 0 ; i <= 18 ; i++){
if(cre[i] != ' ')
credit[i] = cre[i] - '0' ;
}
int odd = mul(credit[18]) + mul(credit[16]) + mul(credit[13]) + mul(credit[11]) +mul(credit[8]) + mul(credit[6]) + mul(credit[3]) + mul(credit[1]);
int even = credit[17] + credit[15] + credit[12] + credit[10] + credit[7] + credit[5] + credit[2] + credit[0] ;
int S = odd + even ;
if(S % 10 == 0){
cout << "Valid" << endl;
}else{
cout << "Invalid" << endl;
}
}
}

int mul(int a){
int sum = 0 ;
a *= 2;
while(a != 0){
sum += a % 10;
a /= 10;
}
return sum ;
}

 

 

 

 

 

謝謝~:)

 
ZeroJudge Forum