Advertisement
joaoaugustom

OrdenarNomes

May 16th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     string Nome[10], aux;
  11.     int i, k, t1, t2;
  12.  
  13.     for  (int i = 0; i < 10; i++)
  14.     {
  15.         getline(cin,Nome[i]);
  16.     }
  17.  
  18.     for  (i = 0; i < 10; i++)
  19.     {
  20.         aux = Nome[i];
  21.         t1 = aux.size();
  22.  
  23.         for  (k = i + 1; k < 10; k++)
  24.         {
  25.             aux = Nome[k];
  26.             t2 = aux.size();
  27.  
  28.             if  (t1 < t2)
  29.             {
  30.                 for  (int j = 0; j < t1; j++)
  31.                 {
  32.                     if  (Nome[i][j] < Nome[k][j]) break;
  33.                    
  34.                     if  (Nome[i][j] > Nome[k][j])
  35.                     {
  36.                         aux = Nome[i];
  37.                         Nome[i] = Nome[k];
  38.                         Nome[k] = aux;
  39.                     }
  40.                 }
  41.             }
  42.             else
  43.             {
  44.                 for  (int j = 0; j < t2; j++)
  45.                 {
  46.                     if  (Nome[i][j] < Nome[k][j]) break;
  47.  
  48.                     if  (Nome[i][j] > Nome[k][j])
  49.                     {
  50.                         aux = Nome[i];
  51.                         Nome[i] = Nome[k];
  52.                         Nome[k] = aux;
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.     }
  58.  
  59.     cout << "\n\n";
  60.  
  61.     for  (int i = 0; i < 10; i++)
  62.     {
  63.         cout << Nome[i] << endl;
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement