272 - TEX Quotes || UVa Online Judge
Problem name: 272 - TEX Quotes
Problem link: 272 - TEX Quotes
Judge: UVa Online Judge
Solution on GitHub: 272 - TEX Quotes
At first you should try to solve the problem on your own. This will increase your thinking power and the ability to solve the program will increase and if you copy directly from here, you will not learn anything. So my advice is to try to solve it yourself first. If not then check this code. Once you understand the code, do it yourself. Don't copy from here.
Best of luck
UVa 272 - TEX Quotes Solution in C++/Cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
string line;
bool open = true;
while (getline(cin, line))
{
int len = line.length();
for (int i = 0; i < len; i++)
{
if (line[i] == '"')
{
if (open)
{
printf("``");
}
else
{
printf("''");
}
open = !open;
}
else
{
printf("%c", line[i]);
}
}
printf("\n");
}
return 0;
}
Thumbnail:
