Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //task: given a string S, count how many times do you need to change letters so that every letter is different
- //code
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int start_s=clock();
- std::string input;
- ifstream file;
- int random;
- /* read input from file
- file.open("KB.inp");
- file >> random >> input;
- cout << "read file";
- */
- /* direct input
- cin >> random >> input;
- */
- std::string alpha="abcdefghijklmnopqrstuvwxyz";
- int answer=0;
- int characterCount=0;
- int temp=0;
- cin >> input;
- int size=input.size();
- for (int i=0;i<26;i++)
- {
- temp=count(input.begin(), input.end(), alpha.at(i));
- characterCount += temp;
- if (temp>0){answer+=temp-1;}
- if (characterCount==size){break;}
- }
- cout << answer << '\n';
- int stop_s=clock();
- cout << "time: " << (stop_s-start_s)/double(CLOCKS_PER_SEC) << " seconds";
- }
- //input
- [character count]
- [string]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement