272 - TEX Quotes

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
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

Post by brianfry713 » Mon Jun 23, 2014 9:35 pm

Don't print a space at the end of a line.
Check input and AC output for thousands of problems on uDebug!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

272 - TEX Quotes

Post by NAbdulla » Wed Jul 30, 2014 4:29 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 272 - TEX Quotes

Post by brianfry713 » Wed Jul 30, 2014 9:24 pm

gets will not return EOF (-1). You could instead use NULL (0):
while(gets(in) != NULL) {
Check input and AC output for thousands of problems on uDebug!

NAbdulla
New poster
Posts: 31
Joined: Wed Jul 30, 2014 3:40 pm
Contact:

Re: 272 - TEX Quotes

Post by NAbdulla » Thu Jul 31, 2014 2:26 pm

Thanks, but there was another wrong, that was for each line I was putting f = 0.

sarowar_csecu
New poster
Posts: 4
Joined: Wed Nov 04, 2009 6:08 am

Re: 272 - TEX Quotes

Post by sarowar_csecu » Thu Sep 11, 2014 2:41 pm

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 272 - TEX Quotes

Post by brianfry713 » Thu Sep 11, 2014 9:19 pm

Remove the first line: /*
Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

sarowar_csecu
New poster
Posts: 4
Joined: Wed Nov 04, 2009 6:08 am

Re: 272 - TEX Quotes

Post by sarowar_csecu » Fri Sep 12, 2014 8:57 am

Accepted. Thanks :)
Sarowar

RocknJon
New poster
Posts: 2
Joined: Sat Sep 27, 2014 12:12 am

Re: 272 - TEX Quotes

Post by RocknJon » Sat Sep 27, 2014 12:14 am

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;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 272 - TEX Quotes

Post by lighted » Mon Sep 29, 2014 2:40 pm

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

lazyplatoon
New poster
Posts: 4
Joined: Wed Dec 10, 2014 5:00 am

Re: 272 - TEX Quotes

Post by lazyplatoon » Wed Dec 10, 2014 5:06 am

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.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 272 - TEX Quotes

Post by lighted » Wed Dec 10, 2014 2:02 pm

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

lazyplatoon
New poster
Posts: 4
Joined: Wed Dec 10, 2014 5:00 am

Re: 272 - TEX Quotes

Post by lazyplatoon » Thu Dec 11, 2014 8:29 am

lighted wrote: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] == '"') {
Thanks man... Silly mistake... :P

FahimShahriar
New poster
Posts: 1
Joined: Mon Jan 05, 2015 2:27 am

Re: 272 - TEX Quotes whats the problm

Post by FahimShahriar » Mon Jan 05, 2015 3:05 am

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 272 - TEX Quotes

Post by brianfry713 » Wed Jan 07, 2015 3:32 am

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!

BaronRED
New poster
Posts: 3
Joined: Sun Jun 28, 2015 4:40 pm

Re: 272 - TEX Quotes

Post by BaronRED » Sun Jun 28, 2015 4:54 pm

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! :D

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;
}

Post Reply

Return to “Volume 2 (200-299)”