I'm doing UVa Problem 10082 and I'm trying to read in some sample input to test my solution. However, when I read in the text '''CCC
it outputs ;;XXX
. Note that there are only 2 semi-colons, when there should be 3 since there are 3 single quotes in the input. Why is getline() ignoring the first single quote?
Here's my code:
#include <iostream>
#include <string>
using namespace std;
char mapToWertyu(char c)
{
char newC = c;
char wertyu[] = {'1','2','3','4','5','6','7','8','9','0','-','=',
'Q','W','E','R','T','Y','U','I','O','P','[',']','\\',
'A','S','D','F','G','H','J','K','L',';','\'',
'Z','X','C','V','B','N','M',',','.','/'};
char qwerty[] = {'~','1','2','3','4','5','6','7','8','9','0','-','=',
'Q','W','E','R','T','Y','U','I','O','P','[',']','\\',
'A','S','D','F','G','H','J','K','L',';','\'',
'Z','X','C','V','B','N','M',',','.','/'};
if(c=='A' || c=='Q' || c=='Z')
return c;
for(int i = 0; i < 47; ++i)
{
if(wertyu[i]==c)
{
newC = qwerty[i];
break;
}
}
return newC;
}
int main()
{
string input;
while(cin.peek()!=-1)
{
getline(cin,input);
for(int i = 0; i < input.length(); ++i)
{
if(input[i]!='\\')
cout << mapToWertyu(input[i]);
}
cin.ignore(1,'\n');
cout << endl;
}
return 0;
}