Skip to content

Instantly share code, notes, and snippets.

@autekroy
Created April 19, 2014 16:20
Show Gist options
  • Save autekroy/11089292 to your computer and use it in GitHub Desktop.
Save autekroy/11089292 to your computer and use it in GitHub Desktop.
ACM-ICPC 4660 - A+B
//This program is for ACM-ICPC 4660 - A+B
//Problem link: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=2661
#include<stdio.h>
#include<string.h>
using namespace std;
int changeBase(int n, int base)
{
int len, sum = 0, tmp;
char num[6];
sprintf(num, "%d", n);//save n in char array (num)
len = strlen(num);
for(int i = 0; i < len-1; i++)
{
tmp = (num[i] - '0');
sum += tmp;
sum *= base;
}
sum = sum + (num[len-1] - '0');
return sum;
}
int findBase(int n)
{
int Min = 1;
while(n != 0)
{
int tmp = n % 10;
if(tmp > Min)
Min = tmp;
n = n / 10;
}
return Min + 1;
}
int main()
{
int n, a, b;
scanf("%d", &n);
while(n--)
{
scanf("%d %d", &a, &b);
//printf("%d %d\n", findBase(a), findBase(b));
printf("%d\n", changeBase(a, findBase(a)) + changeBase(b, findBase(b)) );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment