I'm trying to solve UVAa Online Judge Problem 272 — TeX Quotes.
Input will consist of several lines of text containing an even number of double-quote (
"
) characters. Input is ended with an end-of-file character. The text must be output exactly as it was input except that:
- the first
"
in each pair is replaced by two`
characters:``
and- the second
"
in each pair is replaced by two'
characters:''
.
I don't know why my code gives the wrong answer; I think it's the right answer.
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
int main(){
char kalimat[100000];
int i;
int max;
bool flag=true;
while (scanf("%c",&kalimat)!=EOF){
max=strlen(kalimat);
for (i=0;i<=max;i++){
if (kalimat[i]=='"')
{
if (flag==true){
printf("``");
flag=false;
} else {
printf("''");
flag=true;
}
} else {
printf("%c",kalimat[i]);
}
}
}
return(0);
}