Advertisement
MAT4m

Untitled

Jan 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include<stdio.h>// TO JEST 18
  2. #include<string.h>
  3.  
  4. char strings[10][150];
  5. char ordered[10][150];
  6. int i,j,k;
  7. int ind;
  8. main()
  9. {
  10. printf("INPUT 10 STRINGS\n");
  11. for(i=0;i<10;i++)
  12. {
  13. gets(strings[i]);
  14. }
  15. for(i=0;i<10;i++)
  16. {
  17. ind=0;
  18. for(j=0;j<10;j++)
  19. {
  20. if(strings[i][0]<strings[j][0])
  21. {
  22. ind++;
  23. }
  24. else if(strings[i][0]==strings[j][0])
  25. {
  26. k=0;
  27. while((strings[i][k]==strings[j][k])&&strings[j][k+1]!='\0')
  28. {
  29. if(strlen(strings[i])<strlen(strings[j]))
  30. {
  31. if(strings[i][k+1]=='\0')
  32. {
  33. ind++;
  34. }
  35. else if(strings[i][k+1]<strings[j][k+1])
  36. {
  37. ind++;
  38. }
  39. }
  40. else if(strlen(strings[i])>strlen(strings[j]))
  41. {
  42. if(strings[i][k+1]<strings[j][k+1])
  43. {
  44. ind++;
  45. }
  46. }
  47. k++;
  48. }
  49. }
  50. }
  51. strcpy(ordered[ind],strings[i]);
  52. }
  53.  
  54.  
  55. printf("STRINGS: \n");
  56. for(i=9;i>-1;i--)
  57. {
  58. puts(ordered[i]);
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement