Re: Got Presentation Error. Tried every way. still PE. Plz h
Posted: Mon Jun 23, 2014 9:35 pm
Don't print a space at the end of a line.
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;
}
Code: Select all
Removed after AC
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;
}
Code: Select all
//Removed after AC
Code: Select all
if (str[i] == '"') {
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] == '"') {
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;
}
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;
}