大數加法即可得解。
C++(0.932)
/*******************************************************/
/* UVa 10013 Super long sums */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2012/02/02 */
/*******************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int answer[1000005] = {0};
int main(){
bool blank_line = 0;
int N, M, num1, num2;
while( scanf( "%d", &N ) != EOF ){
for( int i = 0 ; i < N ; i++ ){
scanf( "%d", &M );
memset( answer, 0, sizeof(answer) );
for( int j = M-1 ; j >= 0 ; j-- ){
scanf( "%d%d", &num1, &num2 );
answer[j] += num1+num2;
answer[j+1] += answer[j]/10;
answer[j] %= 10;
}
for( int j = 0 ; j < M ; j++ ){
answer[j+1] += answer[j]/10;
answer[j] %= 10;
}
if( answer[M] ) M++;
if( blank_line ) printf( "\n" );
blank_line = 1;
for( int j = M-1 ; j >= 0 ; j-- )
printf( "%d", answer[j] );
printf( "\n" );
}
}
return 0;
}