http://oj.misakamm.com/JudgeOnline/problem.php?id=1003
#include <fstream> int main() { char bufa[1001] , bufb[1001] ; scanf( "%s%s" , bufa , bufb ) ; int h , i = 0 , j = 0 , k , a[1001] , b[1001] , c[1001] ; bool onoff ; for ( h = 0 ; bufa[h] ; ++h ) ; while ( h > 0 ) a[++i] = bufa[--h] - '0' ; for ( h = 0 ; bufb[h] ; ++h ) ; while ( h > 0 ) b[++j] = bufb[--h] - '0' ; if ( i > j ) while ( j < i ) b[++j] = 0 ; else while ( i < j ) a[++i] = 0 ; c[1] = 0 ; for ( h = 1 ; h <= i ; ++h ) { c[h] += a[h] + b[h] ; c[h+1] = c[h] / 10 ; c[h] %= 10 ; } if ( c[h] == 0 ) --h ; while ( h > 0 ) printf( "%d" , c[h--]) ; }