/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <map>
#include <algorithm>
int main()
{
std::string word;
std::cout << "Write your word: ";
std::getline(std::cin, word);
//print out the word before replacing with 1 and 2
std::cout<<"Before transformation: "<<word<<std::endl;
std::map<char, int> charCount; //this map will keep count of the repeating characters
//iterate through each character in the input word and populate the map
for(char &c: word)
{
charCount[std::tolower(c)]++;//increment the value by 1
}
//replace the repeating characters by 1 and non-repeating by 2
for(char &c: word)
{
if(charCount.at(std::tolower(c)) > 1)
{
c = '1';
}
else
{
c = '2';
}
}
//print out the word after transformation
std::cout<<"After transformation: "<<word<<std::endl;
return 0;
}