Content

Friday, August 24, 2018

1214 - Large Division

Problem Link

এই লিঙ্কটা একবার দেখে আসি তাহলে এই প্রব্লেমটা করতে আর সময় লাগবে না আশা করি।

My Solution in C++:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int T,t;
  7.  
  8.     cin>>T;
  9.  
  10.     for(t=1; t<=T; t++)
  11.     {
  12.         char bhajjo[1000];
  13.         long long i,bhajok,bhagshesh=0; /// 18| 2592 | 144
  14.         scanf("%s",bhajjo);            /// bhajok | bhajjo | bhagfol
  15.         scanf("%lld",&bhajok);
  16.  
  17.         int l=strlen(bhajjo);
  18.  
  19.         for(i=0; i<l; i++)
  20.         {
  21.             if(bhajjo[i]=='-')
  22.                 bhajjo[i]='0';
  23.         }
  24.  
  25.         for(i=0; i<l; i++)
  26.         {
  27.             bhagshesh = ((bhagshesh*10) + (bhajjo[i]-'0') )%bhajok; // Amra character theke integer e convert kore nilam '0' biyog kore
  28.         }
  29.  
  30.         if(bhagshesh==0)
  31.             cout<<"Case "<<t<<": divisible"<<endl;
  32.         else
  33.             cout<<"Case "<<t<<": not divisible"<<endl;
  34.     }
  35.  
  36.     return 0;
  37. }

No comments:

Post a Comment