Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. ifstream f("interesant.in");
  5. ofstream g("interesant.out");
  6.  
  7. int main()
  8. {
  9.     int p, n; f >> p >> n;
  10.     char mat[n][5001];
  11.  
  12.     for(int i = 0; i<n; ++i){
  13.         f >> mat[i];
  14.     }
  15.  
  16.     if(p==1)
  17.     {
  18.         bool sortat = false;
  19.         while(!sortat)
  20.         {
  21.             sortat = true;
  22.             for(int i = 0; i<n-1; ++i)
  23.             {
  24.                 if(strlen(mat[i]) > strlen(mat[i+1])){
  25.                     char temp[5001];
  26.                     strcpy(temp, mat[i]);
  27.                     strcpy(mat[i], mat[i+1]);
  28.                     strcpy(mat[i+1], temp);
  29.                     sortat = false;
  30.                 }
  31.                 if(strlen(mat[i]) == strlen(mat[i+1]))
  32.                 {
  33.                     if(strcmp(mat[i], mat[i+1]) < 0)
  34.                     {
  35.                         char temp[5001];
  36.                         strcpy(temp, mat[i]);
  37.                         strcpy(mat[i], mat[i+1]);
  38.                         strcpy(mat[i+1], temp);
  39.                         sortat = false;
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.  
  45.         g << mat[n-1];
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement