fjnu 1946 Base Comparator

来源:互联网 发布:淘宝怎么不能合并付款 编辑:程序博客网 时间:2024/05/16 18:40

Description

DigiCircuits Inc. is a software company that develops software simulators for digital circuits. A very frequently used component of its software, named the comparator, is a simulated circuit that compares numbers expressed in different numerical bases. More exactly, this component receives two numbers, each one in a possible different base, and decides if the first number is less than, equal to or greater than the second number.
The numerical bases that may appear vary from 1 to 9. Remember that a number expressed in base b uses only digits less than b.

Your task is to develop a program that simulates the function of the comparator component.

Input

The input contains several test cases, each one of them in a separate line. Each test case has four numerical strings, each two of them separated by a blank character, say


s b t c

Strings b and c are one-character strings. They represent the bases for the first and third strings s and t, respectively.

The end of the input is denoted by the end of file.

Output

Output text for each input case is presented in the same order that input is read. For each test case the answer must be a left aligned answer-character corresponding to the input. This character must be < , = or > , accordingly to the fact that the first string represents a numerical value less than, equal to or greater that the represented by the third string.

Sample Input

54 6 71 8110 2 6 73 4 3 914 7 1000 2

Sample Output

<==>

 

KEY:这个题我的思路是把两个数转化到相同进制里面(比如10进制),然后比较,问题在于他的输入的数比较大要用字符串存放,所得的数也较大,用用unsigned long存放;

 

Source:

#include
<iostream.h>
#include
<math.h>
#include
<string.h>
//using namespace std;

unsigned 
long translate(char str[],int base)
{
    
int len=strlen(str);
    unsigned 
long sum=0;
    
int i,k;
    
for(i=len-1,k=0;i>=0;i--,k++)
    
{
        
int t=str[i]-'0';
        sum
+=t*(unsigned long)pow(base,k);
    }

    
return sum;
}


int main()
{
//    freopen("fjnu_1946.in","r",stdin);
    char a1[1000],a2[1000];
    
int b1,b2;
    unsigned 
long t1,t2;
    
while(cin>>a1>>b1>>a2>>b2)
    
{
        t1
=translate(a1,b1);
        t2
=translate(a2,b2);
        
if(t1==t2) cout<<"="<<endl;
        
if(t1>t2) cout<<">"<<endl;
        
if(t1<t2) cout<<"<"<<endl;
    }

    
return 0;
}





 

 

原创粉丝点击