Advertisement
madidino

teza14-sub3-1

Feb 21st, 2024
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     char s[201];
  8.     int n;
  9.     cin>>n;
  10.     cin.ignore();
  11.     cin.getline(s,200);
  12.     char *p;
  13.     p=strtok(s," ");
  14.     int k=n;
  15.     while(p)
  16.     {
  17.         int x=strlen(p);
  18.         if(x>n)
  19.         {
  20.             cout<<"IMPOSIBIL";
  21.             break;
  22.         }
  23.         if(k<x)
  24.         {
  25.             while(k)
  26.             {
  27.                 cout<<"*";
  28.                 k--;
  29.             }
  30.             k=n-x-1;
  31.             cout<<endl<<p<<" ";
  32.         }
  33.         else if(k==x)
  34.         {
  35.             cout<<p<<endl;
  36.             k=n;
  37.         }
  38.         else
  39.         {
  40.             k=k-x-1;
  41.             cout<<p<<" ";
  42.         }
  43.         p=strtok(NULL," ");
  44.     }
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement