提交时间:2024-07-30 18:17:33

运行 ID: 159713

# include <bits/stdc++.h> using namespace std ; int c2i ( char c ) { if ( c >= '0' && c <= '9' ) { return c - '0' ; } else { return c - 'A' + 10 ; } } char i2c ( int i ) { if ( i < 10 ) { return char ( '0' + i ) ; } else { return char ( 'A' + i - 10 ) ; } } long long m2t ( string s , int m ) { long long ans = 0 ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { ans *= m ; ans += c2i ( s [i] ) ; } return ans ; } string t2n ( long long x , int n ) { string s = "" ; while ( x != 0 ) { int a = x % n ; x = ( x - ( x % n ) ) / n ; s = i2c ( a ) + s ; } return s ; } int main ( ) { int n , a1 , b1 , sum ; string a , b ; cin >> n >> a >> b ; a1 = m2t ( a , n ) , b1 = m2t ( b , n ) ; sum = a1 + b1 ; cout << t2n ( sum , n ) << endl ; return 0 ; }