272 - TEX Quotes
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Got Presentation Error. Tried every way. still PE. Plz h
Don't print a space at the end of a line.
Check input and AC output for thousands of problems on uDebug!
272 - TEX Quotes
Whats wrong with my code
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
int i, j, k, l1, f;
char in[10000], out[10000];
while(gets(in) != EOF){
l1 = strlen(in);
f = 0;
for(i = 0, j = 0; i < l1; i++){
if(in[i] == '"' && f == 0){
out[j] = '`';
j++;
out[j] = '`';
j++;
f = 1;
}
else if(in[i] == '"' && f == 1){
out[j] = 39;
j++;
out[j] = 39;
j++;
f = 0;
}
else{
out[j] = in[i];
j++;
}
}
out[j] == '\0';
printf("%s\n", out);
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 272 - TEX Quotes
gets will not return EOF (-1). You could instead use NULL (0):
while(gets(in) != NULL) {
while(gets(in) != NULL) {
Check input and AC output for thousands of problems on uDebug!
Re: 272 - TEX Quotes
Thanks, but there was another wrong, that was for each line I was putting f = 0.
-
- New poster
- Posts: 4
- Joined: Wed Nov 04, 2009 6:08 am
Re: 272 - TEX Quotes
What's wrong! Getting WA. Please help.
Code: Select all
Removed after AC
Last edited by sarowar_csecu on Fri Sep 12, 2014 8:56 am, edited 1 time in total.
Sarowar
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 272 - TEX Quotes
Remove the first line: /*
Always print a newline char at the end of the last line.
Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 4
- Joined: Wed Nov 04, 2009 6:08 am
Re: 272 - TEX Quotes
Hello, I sent my code like 6 times but I keep gettin Wrong Answer, please help me. Btw is C++
Code: Select all
#include <stdio.h>
#include <string.h>
//#define MAX 10000000
int main()
{
char Original[1000000]="";
int par=0;
while(gets(Original))
{
int l=strlen(Original);
for (int i = 0; i < l; i++)
{
if(Original[i]=='"')
{
par++;
if(par%2==0)
{
printf("%c%c",39,39);
}
else
{
printf("%c%c",96,96);
}
}
else
{
printf("%c",Original[i]);
}
}
}
return 0;
}
Re: 272 - TEX Quotes
Print newline after each line processing.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 4
- Joined: Wed Dec 10, 2014 5:00 am
Re: 272 - TEX Quotes
I'm getting wrong answer... Can you please tell me what's the problem??
Code: Select all
//Removed after AC
Last edited by lazyplatoon on Thu Dec 11, 2014 8:28 am, edited 1 time in total.
Re: 272 - TEX Quotes
Don't set count to 0 in loop. It should be set to 0 once, before loop. Change line to
Code: Select all
if (str[i] == '"') {
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- New poster
- Posts: 4
- Joined: Wed Dec 10, 2014 5:00 am
Re: 272 - TEX Quotes
Thanks man... Silly mistake...lighted wrote:Don't set count to 0 in loop. It should be set to 0 once, before loop. Change line toCode: Select all
if (str[i] == '"') {

-
- New poster
- Posts: 1
- Joined: Mon Jan 05, 2015 2:27 am
Re: 272 - TEX Quotes whats the problm
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
int i,j=0,f;
char a[1000],b[1000];
gets(a);
f=0;
for (i=0;a[i]!='\0';i++)
{
if (a[i]=='"'&& f==0)
{
b[j]='`';
j++;
b[j]='`';
j++;
f=1;
}
else if (a[i]=='"' && f==1)
{ b[j]=39;
j++;
b[j]=39;
j++;
f=0;
}
else
{
b[j]=a[i];
j++;
}
}
b[j]='\0';
printf("%s",b);
return 0;
}

Last edited by brianfry713 on Wed Jan 07, 2015 3:31 am, edited 1 time in total.
Reason: Added code blocks
Reason: Added code blocks
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 272 - TEX Quotes
Doesn't match the sample I/O, your code is only printing the first line.
Check input and AC output for thousands of problems on uDebug!
Re: 272 - TEX Quotes
Hi guys, I've tried what I think is the naive approach but I can't figure out why it takes so much to execute (I got TLE) and how to improve it, can somebody help me? I've seen so many complicated programs for this problem while mine is very simple, what I'm ignoring?
Instead of reading the whole input, process it and print it out, my program proceed char by char; what I can think of is that start reading from stdin and start printing on stdout might take some time instead of read all and print all, but dunno...
Thanks in advance!
Instead of reading the whole input, process it and print it out, my program proceed char by char; what I can think of is that start reading from stdin and start printing on stdout might take some time instead of read all and print all, but dunno...
Thanks in advance!

Code: Select all
#include <stdio.h>
int main (){
bool quotes = 0; //true = the first (``) - false = the second ('')
char c;
do {
scanf ("%c", &c);
if (c != '"'){
printf("%c", c);
} else {
quotes = !quotes;
printf ((quotes)? "``" : "''");
}
} while (c != EOF);
return 0;
}