Guest User

Untitled

a guest
Feb 13th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main(){
  6. int n;
  7. cout << "please enter n" << endl;
  8. cin >> n;
  9. int tot[10];
  10. bool cantuse[10];
  11. string sample[n];
  12. for (int i = 1; i< n+1; i++){
  13. cout << "please enter string number " << i << endl;
  14. cin >> sample [i-1];
  15. }
  16. for (int j = 0; j <n; j++){
  17. int tens = 1;
  18. for (int k = sample[j].length()-1; k>-1; k-1){
  19. if (k==0){
  20. cantuse[sample[j][k] - 'a'] = true;
  21. }
  22. tot[sample[j][k] - 'a'] += tens;
  23. tens *= 10;
  24. }
  25. }
  26. vector <pair <int, bool> > one;
  27. for (int i = 0; i < 10; i++)one.push_back(make_pair(tot[i], cantuse[i]));
  28. sort(one.begin(),one.end());
  29. int del;
  30. for (int i = 0; i<10 ; i++){
  31. if(one[i].second == false) del = i;
  32. if(one[i].second == false) break;
  33. }
  34. one.erase(one.begin()+del,one.begin()+del+1);
  35. int ans;
  36. for (int i = 0; i<9; i++){
  37. ans += one[i].first *(i+1);
  38. }
  39. cout << ans;
  40. }
Add Comment
Please, Sign In to add comment