Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct bignum
  5. {
  6.        int x [ 10050 ], l;
  7.        
  8.        bignum ( int t ) { memset ( x , 0 , sizeof x ); l = 1; }
  9.        bignum ( )
  10.        {
  11.               char s [ 10050 ];
  12.               memset ( x , 0 , sizeof x );
  13.              
  14.               scanf ( "%s" , &s );
  15.              
  16.               for ( int i = 0; i < strlen ( s ); i++ )
  17.                   x[strlen ( s )-i-1] = s[i] - '0';
  18.              
  19.               l = strlen ( s );
  20.        }
  21.        
  22.        void PUTA ( int t )
  23.        {
  24.             for ( int i = 0; i < l; i++ )
  25.                 x[i] *= t;
  26.            
  27.             for ( int i = 0; i < l; i++ )
  28.             {
  29.                 x[i+1] += x[i] / 10;
  30.                 x[i] %= 10;
  31.             }
  32.            
  33.             while ( x[l] )
  34.             {
  35.                   x[l+1] = x[l] / 10;
  36.                   x[l] %= 10;
  37.                   l++;
  38.             }
  39.        }
  40.        
  41.        bignum operator * ( const bignum &t )
  42.        {
  43.             bignum ret = 0;  
  44.              
  45.             for ( int i = 0; i < l; i++ )
  46.                 for ( int j = 0; j < t.l; j++ )
  47.                     ret.x[i+j] += x[i] * t.x[j];
  48.            
  49.             ret.l = t.l + l - 1;
  50.            
  51.             for ( int i = 0; i < ret.l; i++ )
  52.             {
  53.                 ret.x[i+1] += ret.x[i] / 10;
  54.                 ret.x[i] %= 10;
  55.             }
  56.            
  57.             while ( ret.x[ret.l] )
  58.             {
  59.                   ret.x[ret.l+1] = ret.x[ret.l] / 10;
  60.                   ret.x[ret.l] %= 10;
  61.                   ret.l++;
  62.             }
  63.            
  64.             return ret;
  65.        }
  66.        
  67.        void PRINT()
  68.        {
  69.             for ( int i = l - 1; i >= 0; i-- )
  70.                 printf ( "%d" , x[i] );
  71.            
  72.             printf ( "\n" );
  73.        }
  74.        
  75.        bool NULA()
  76.        {
  77.             if ( l == 1 && x[0] == 0 )
  78.                return true;
  79.            
  80.             return false;
  81.        }
  82. };
  83.  
  84. void SOLVE()
  85. {
  86.      bignum BIG1, BIG2;
  87.      
  88.      if ( BIG1.NULA() || BIG2.NULA() )
  89.      {
  90.            printf ( "0\n" );
  91.           return;
  92.      }
  93.      
  94.      BIG1 = BIG1 * BIG2;
  95.      
  96.      BIG1.PRINT();
  97.  
  98. }
  99.  
  100. int main()
  101. {
  102.     int n;
  103.  
  104.     scanf ( "%d" , &n );
  105.  
  106.     for ( int i = 0; i < n; i++ )
  107.         SOLVE();
  108.  
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement