Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- char s[257],t[257][257],*p,c[257];
- int k=1;
- void citire()
- { cin.get(s,256);
- p=strtok(s," ");
- while(p!=NULL)
- { strcpy(t[k],p);
- k++;
- p=strtok(NULL," ");
- }
- int ok=0,i,x,y;
- k--;
- do
- {ok=1;
- for(i=1;i<=k-1;i++)
- { x=strlen(t[i]);
- y=strlen(t[i+1]);
- if(x<y)
- { ok=0;
- strcpy(c,t[i]);
- strcpy(t[i],t[i+1]);
- t[i][y+1]=NULL;
- strcpy(t[i+1],c);
- t[i+1][x+1]=NULL;
- c[0]=NULL;
- }
- else
- { if(x==y)
- { if(strcmp(t[i],t[i+1])>0)
- {ok=0;
- strcpy(c,t[i]);
- strcpy(t[i],t[i+1]);
- t[i][y+1]=NULL;
- strcpy(t[i+1],c);
- t[i+1][x+1]=NULL;
- c[0]=NULL;
- }
- }
- }
- }
- }while(ok==0);
- for(i=1;i<=k;i++)
- cout<<t[i]<<endl;
- }
- int main()
- {
- citire();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement