Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main(){
- int n;
- cout << "please enter n" << endl;
- cin >> n;
- int tot[10];
- bool cantuse[10];
- string sample[n];
- for (int i = 1; i< n+1; i++){
- cout << "please enter string number " << i << endl;
- cin >> sample [i-1];
- }
- for (int j = 0; j <n; j++){
- int tens = 1;
- for (int k = sample[j].length()-1; k>-1; k-1){
- if (k==0){
- cantuse[sample[j][k] - 'a'] = true;
- }
- tot[sample[j][k] - 'a'] += tens;
- tens *= 10;
- }
- }
- vector <pair <int, bool> > one;
- for (int i = 0; i < 10; i++)one.push_back(make_pair(tot[i], cantuse[i]));
- sort(one.begin(),one.end());
- int del;
- for (int i = 0; i<10 ; i++){
- if(one[i].second == false) del = i;
- if(one[i].second == false) break;
- }
- one.erase(one.begin()+del,one.begin()+del+1);
- int ans;
- for (int i = 0; i<9; i++){
- ans += one[i].first *(i+1);
- }
- cout << ans;
- }
Add Comment
Please, Sign In to add comment