193030

1.7.3 lexicographic

May 8th, 2021
622
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Write a function which takes arugements of strings
  2. // and returns the lowest lexiographic one
  3.  
  4. #include <iostream>
  5. #include <tuple>
  6. using namespace std;
  7. string myArray[4] = { "12345678", "01", "12345", "012" };
  8. int n;
  9. pair <string, int> minStr(string arr[], int size )
  10. {
  11.     string minString = arr[0];
  12.     int position = 0;
  13.     for(int i = 1; i<size; i++)
  14.     {
  15.         if(arr[i] < minString)
  16.         {
  17.             minString = arr[i];
  18.             position = i;
  19.         }
  20.     }
  21.     return { minString, position };
  22. }
  23. int main()
  24. {
  25.     string s;
  26.     int i;
  27.     n = sizeof(myArray) / sizeof(myArray[0]);
  28.     tie(s, i) = minStr(myArray, n);
  29.     cout << s << " " << i << endl;
  30.    
  31.  
  32. }
  33.  
RAW Paste Data