The following program is my ACcepted code for ACM-ICPC Archive-4660 .
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃ACM-ICPC Archive 4660 的AC code!
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃ACM-ICPC Archive 4660 的AC code!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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; | |
} |
Please feel free to use it after adding this blog as an reference. (http://autekroy.blogspot.tw) If there is any mistake or comment, please let me know. :D
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!