A Math Puzzle | ||||||
| ||||||
Description | ||||||
Given a duodecimal number A, then translate it into decimal number B, can you judge if B MOD 11 equals 0? | ||||||
Input | ||||||
There are multiple test cases. Each test case has one duodecimal number A (contain “0123456789AB”). (The length of A <= 20) | ||||||
Output | ||||||
For each case, if B MOD 11 equals 0, output “YES”. Otherwise, output “NO”. | ||||||
Sample Input | ||||||
1 2 3 4 5 6 7 8 9 A B 1B | ||||||
Sample Output | ||||||
NO NO NO NO NO NO NO NO NO NO YES NO | ||||||
Hint | ||||||
duodecimal(十二进制) |
考点:进制转换+取模运算
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string A;
while(cin>>A){
int len=A.length();
int sum=0;
for(int i=0; i<n; i++){
if(A[i]=='A'){
sum=sum*12+10;
}else if(X[i]=='B'){
sum=sum*12+11;
}else{
sum=sum*12+X[i]-'0';
}if(sum>=11){
sum%=11;
}
}
if(sum==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}