Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. string s;
  6. int l;
  7.  
  8. void selection_sort()
  9. {
  10.     for (int i = 0;i < 15;i++){
  11.         int t = i;
  12.         for (int j = i+1;j < l;j++){
  13.             if (s[t] > s[j])t = j;
  14.         }
  15.         if (i != t){
  16.             char ch = s[t];
  17.             s[t] = s[i];
  18.             s[i] = ch;
  19.         }
  20.     }
  21. }
  22. int main()
  23. {
  24.     int t, result = 0;
  25.     scanf("%d", &t);
  26.     string test_s;
  27.     char ch = 'a';
  28.     for (int i = 0;i < 26;i++, ch++){
  29.         test_s[i] = ch;
  30.     }
  31.     while (t--){
  32.         cin >> s;
  33.         l = s.length();
  34.  
  35.         selection_sort();
  36.  
  37.         for (int i = 0;i < 15;i++){
  38.             int carry = 1;
  39.             for (int j = 0;s[i] != test_s[j];j++)carry++;
  40.             result += carry;
  41.         }
  42.     }
  43.     printf("%d\n", result);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement