Advertisement
csetanzil

Untitled

Nov 30th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. /// The text splitting
  2.  
  3. #include<bits/stdc++.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char s[101];
  9.     int n,p,q,i,j,mul=1,m,chk,chk2;
  10.     cin>>n>>p>>q;
  11.     cin>>s;
  12.     int sum =0;
  13.     while(sum<n)
  14.     {
  15.         sum = mul*p + mul* q;
  16.         mul++;
  17.     }
  18.     if(sum==n)
  19.     {
  20.         mul--;
  21.         mul = mul*2;
  22.         cout<<mul<<endl;
  23.         i = 0;
  24.         m=0;
  25.         mul= mul/2;
  26.         while(mul)
  27.         {
  28.  
  29.         for(i; i<(m+p);i++)
  30.         cout<<s[i];
  31.         m = i;
  32.         cout<<endl;
  33.         for(j=i;j<(m+q);j++)
  34.             cout<<s[j];
  35.         m = i;
  36.         cout<<endl;
  37.         mul--;
  38.         }
  39.     }
  40.     else
  41.     {
  42.         if(p>q)
  43.             {
  44.               chk = q;
  45.               chk2 = p;
  46.             }
  47.  
  48.         else
  49.             {
  50.               chk = p;
  51.               chk2 = q;
  52.             }
  53.         if(n%chk==0)
  54.         {
  55.             mul = n/chk;
  56.             cout<<mul<<endl;
  57.  
  58.                 j=1;
  59.                 for(i=0;s[i]!='\0';i++,j++)
  60.                 {
  61.                     cout<<s[i];
  62.                     if(j==chk)
  63.                     {
  64.                         cout<<endl;
  65.                         j = 0;
  66.                     }
  67.                 }
  68.         }
  69.         else if(n%chk2==0)
  70.         {
  71.            mul = n/chk2;
  72.             cout<<mul<<endl;
  73.  
  74.                 j=1;
  75.                 for(i=0;s[i]!='\0';i++,j++)
  76.                 {
  77.                     cout<<s[i];
  78.                     if(j==chk2)
  79.                     {
  80.                         cout<<endl;
  81.                         j = 0;
  82.                     }
  83.                 }
  84.         }
  85.         else
  86.         cout<<"-1";
  87.     }
  88.     return 0;
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement