pat 甲级 1010

pat 甲级 1010

1.不仅仅要考虑36以内的进制,radix可以很大

2. 题目数据中radix的范围很大,所以数据需要用long long.


#include
using namespace std;

long long change_radix(string str, long long radix)
{
  long long t = str[0]>'9'?str[0]-'a'+10:str[0]-'0';
  for(int i = 1;i'9'?str[i]-'a'+10:str[i]-'0');
  return t;
}

int main()
{
  string a, b;
  long long tag, radix1, radix2 = 0;
  cin>>a>>b>>tag>>radix1;
  if(tag == 2)
    swap(a,b);
  long long num1 = change_radix(a,radix1);
  for(int i = 0;iradix2)
      radix2 = b[i];
  }
  radix2 = (radix2>'9'?radix2-'a'+10:radix2-'0')+1;
  if(a.size()>1;
    long long num2 = change_radix(b,middle);
    if(num2 == num1)
    {
      cout<

你可能感兴趣的:(PAT甲级)