Page 9 of 10

Re: Got Presentation Error. Tried every way. still PE. Plz h

Posted: Mon Jun 23, 2014 9:35 pm
by brianfry713
Don't print a space at the end of a line.

272 - TEX Quotes

Posted: Wed Jul 30, 2014 4:29 pm
by NAbdulla
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;
}

Re: 272 - TEX Quotes

Posted: Wed Jul 30, 2014 9:24 pm
by brianfry713
gets will not return EOF (-1). You could instead use NULL (0):
while(gets(in) != NULL) {

Re: 272 - TEX Quotes

Posted: Thu Jul 31, 2014 2:26 pm
by NAbdulla
Thanks, but there was another wrong, that was for each line I was putting f = 0.

Re: 272 - TEX Quotes

Posted: Thu Sep 11, 2014 2:41 pm
by sarowar_csecu
What's wrong! Getting WA. Please help.

Code: Select all

Removed after AC
 

Re: 272 - TEX Quotes

Posted: Thu Sep 11, 2014 9:19 pm
by brianfry713
Remove the first line: /*
Always print a newline char at the end of the last line.

Re: 272 - TEX Quotes

Posted: Fri Sep 12, 2014 8:57 am
by sarowar_csecu
Accepted. Thanks :)

Re: 272 - TEX Quotes

Posted: Sat Sep 27, 2014 12:14 am
by RocknJon
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

Posted: Mon Sep 29, 2014 2:40 pm
by lighted
Print newline after each line processing.

Re: 272 - TEX Quotes

Posted: Wed Dec 10, 2014 5:06 am
by lazyplatoon
I'm getting wrong answer... Can you please tell me what's the problem??

Code: Select all

//Removed after AC

Re: 272 - TEX Quotes

Posted: Wed Dec 10, 2014 2:02 pm
by lighted
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] == '"') {

Re: 272 - TEX Quotes

Posted: Thu Dec 11, 2014 8:29 am
by lazyplatoon
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

Re: 272 - TEX Quotes whats the problm

Posted: Mon Jan 05, 2015 3:05 am
by FahimShahriar

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

Re: 272 - TEX Quotes

Posted: Wed Jan 07, 2015 3:32 am
by brianfry713
Doesn't match the sample I/O, your code is only printing the first line.

Re: 272 - TEX Quotes

Posted: Sun Jun 28, 2015 4:54 pm
by BaronRED
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;
}