Page 3 of 4

Posted: Fri Feb 04, 2005 6:43 pm
by Digit
Perhaps your arrays are too small. Words to ignore can be at most 20 characters long, at title at most 400 characters according to your code. May be this is not enough?
I really don't know, but this may be a reason.

Posted: Sat Feb 05, 2005 7:41 am
by ImLazy
Thank you Digit.
But I'm afraid array length is not the error. I have done a test about the Online Judge of problem #123, and got the result as follows.

Code: Select all

In the Input of Online-Judge of 123, There are:
20 ignore words
98 titles
64 non ignore words(Maybe some of them are identical), so at most 64 keywords
the biggest length of title is 41 characters
the biggest length of word is 13 characters
That's not a very big capability, so my arrays are big enough. Furthermore, if a array is not big enough, the judge status will be Runtime Error, but I get WA. So there must be some other error that I really can't find out.
Thank you any way.

Posted: Sat Feb 05, 2005 10:04 am
by chunyi81
ImLazy wrote:Dear chunyi81, would like to tell me whether your output for the long input above is identical as mine.
Yes, my AC program gives the same output.
I'm not sure what is wrong with your code. If u search the forum, there are some useful sample I/O.

Posted: Sun Feb 06, 2005 6:24 pm
by ImLazy
OK, now I get AC. The error is the printf("\b\n"); Becuase '\b' is not accepted by the Online-Judge system.

compile error in 187 and 123 plz heeeeeeeelp!!

Posted: Sat Sep 03, 2005 9:07 am
by Sakib
Anybody please tell me why compile error in these two

// problem 187

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int i,j,k,n,m,r,p,q,b,c;
double a,sum;
char s[20];
struct account
{
int n;
char name[31];
int len;
double val;
}acc[101];
struct paccount
{
int n;
account acc[101];
}pacc[5000];


int num(char c1,char c2,char c3)
{
return (((int)c1-48)*100) + (((int)c2-48)*10) + ((int)c3-48);
}

double conv(char t[],int n)
{
unsigned long i,j=1,k=0,r;
double a=0;
i=n-1;
r=n-9;
while(i>=r)
{
if(isspace(t))break;
if(t=='-'){k=1;break;};
a=a+(double)(((int)t-48)*j);
j=j*10;
i--;
}
a=a/100.0;
if(k==1)return (-1.0) * a;
return a;
}


void main()
{
m=0;
k=0;
b=0;
int v=0;
int w=0;
while(gets(s)!=NULL)
{
r=strlen(s);
/////////////////////////////
for(i=r-1;i>=0;i--)
{
if(s!=' ')break;
r--;
}
if(m==1){ if(s[0]=='0'&&s[1]=='0'&&s[2]=='0')break; }
else { if(s[0]=='0'&&s[1]=='0'&&s[2]=='0'){m=1;continue;} }
j=0;
if(m==0)
{
acc[k].n = num(s[0],s[1],s[2]);
for(i=3;i<r;i++){acc[k].name[j++] = s;}
acc[k].len = j;
k++;
}
///////////////////////////////
else
{
p = num(s[0],s[1],s[2]);
if(c==0){b=p;c=1;}
///////////////////////////
if(p!=b)
{
pacc[w].n = b;
b=p;
sum=0.0;
for(i=0;i<k;i++)sum = sum + acc.val;
if(sum!=0)
{
for(i=0;i<k;i++)
{
pacc[w].acc.n = acc.n;
for(j=0;j<acc.len;j++){pacc[w].acc.name[j] = acc[i].name[j];}
pacc[w].acc[i].val = acc[i].val;
}
w++;
}
for(i=0;i<k;i++)acc[i].val=0.0;
}
///////////////////////////
q = num(s[3],s[4],s[5]);
a = conv(s,r);
for(i=0;i<k;i++)
{
if(acc[i].n == q){acc[i].val = a;break;}
}
///////////////////////////////
}
}
sum=0.0;
for(i=0;i<k;i++)sum = sum + acc[i].val;
if(sum!=0)
{
pacc[w].n = p;
for(i=0;i<k;i++)
{
pacc[w].acc[i].n = acc[i].n;
for(j=0;j<acc[i].len;j++){pacc[w].acc[i].name[j] = acc[i].name[j];}
pacc[w].acc[i].val = acc[i].val;
}
w++;
}
for(i=0;i<w;i++)
{
sum=0.0;
printf("*** Transaction %d is out of balance ***\n",pacc[i].n);
for(j=0;j<k;j++)
{
if(pacc[i].acc[j].val == 0.0)continue;
printf("%d ",pacc[i].acc[j].n);
for(int z=0;z<acc[j].len;z++)printf("%c",pacc[i].acc[j].name[z]);
for(z=acc[j].len;z<=20;z++)printf(" ");
printf("%20.2lf\n",pacc[i].acc[j].val);
sum = sum + pacc[i].acc[j].val;
}
printf("999 Out of Balance");
printf("%27.2lf\n\n",sum);
}
}



// Problem 123 Searching Quickly

#include<stdio.h>
#include<string.h>
#include<ctype.h>
////////////////////////////////////////////
int i,j,k,n,m,r,b;
struct positions
{
int x;
int y;
}poss[101];
int tl[501],sl[101];
char s[100][30];
char t[501][101];
//////////////////////////////////////
void match(char s[],int p,char t[],int q)
{
int i,j,b,e;
for(i=0;i<p;i++)
{
if(tolower(s[i])==tolower(t[0]))
{
if(i!=0){if(s[i-1]!=' ')continue;}
b=i;
e=0;
for(j=1;j<q;j++)
{
if(tolower(s[i+j])!=tolower(t[j]))break;
e++;
}
if(e==q-1 && s[b+q]==' ')
{
for(j=b;j<b+q;j++)
{
s[j]=tolower(s[j]);
}
}
}
}
}

///////////////////////////////////////////////////////
int isgtr(char s[],int p,char t[],int q)
{
int i,j,k,bs,es,bt,et;
for(i=0;i<p;i++){ if(isupper(s[i])) { bs=i;break; } }
for(i=p-1;i>=0;i--){ if(isupper(s[i])) { es=i+1;break; } }
for(i=0;i<q;i++){ if(isupper(t[i])) { bt=i;break; } }
for(i=q-1;i>=0;i--){ if(isupper(t[i])) { et=i+1;break; } }
j=bt;
for(i=bs;i<es && j<et;i++)
{
if(s[i] > t[j])return 2;
if(s[i] < t[j])return 1;
j++;
}
if((es-bs) < (et-bt))return 1;
if((es-bs) > (et-bt))return 2;
return 0;
}
///////////////////////////////////////////////////////

void main()
{
////////////// INPUTS ///////////////////////////////////
i=0;
while(scanf("%s",s[i])==1)
{
if(s[i][0]==':' && s[i][1]==':')break;
sl[i]=strlen(s[i]);
i++;
}
n=i;
i=0;
while(gets(t[i])!=NULL)
{
tl[i]=strlen(t[i]);
strupr(t[i]);
for(j=0;j<n;j++){match(t[i],tl[i],s[j],sl[j]);}
////////////////////////////////////////////////////
b=0;k=0;
for(j=0;j<tl[i];j++)
{
if(isupper(t[i][j]))
{
if(b == 0){ poss[k++].x = j; b = 1; }
}
else { b = 0; }
}
r=k;
b=0;k--;
for(j=tl[i]-1;j>=0;j--)
{
if(isupper(t[i][j]))
{
if(b == 0){ poss[k--].y = j; b = 1; }
}
else { b = 0; }
}
//////////////////////////////////////////////
for(k=0;k<tl[i];k++){t[i][k]=tolower(t[i][k]);}
b=i;
for(j=1;j<r;j++)
{
i++;
tl[i]=tl;
for(k=0;k<tl;k++){t[i][k]=t[k];}
for(k=poss[j].x;k<=poss[j].y;k++){t[i][k]=toupper(t[i][k]);}
}
for(k=poss[0].x;k<=poss[0].y;k++){t[k]=toupper(t[k]);}
////////////////////////////////////////////////////
i++;
}
m=i;
///////// PROCESSING ////////////////////////////////////

char tmp[200];
int temp;
for(i=m-1;i>=0;i--)
{
for(j=0;j<i;j++)
{
if(isgtr(t[j],tl[j],t[j+1],tl[j+1])==2)
{
strcpy(tmp,t[j]);
strcpy(t[j],t[j+1]);
strcpy(t[j+1],tmp);
temp=tl[j];
tl[j]=tl[j+1];
tl[j+1]=temp;
}
}
}

/////////// PRINTING ////////////////////////////
for(i=0;i<m;i++)
{
for(j=0;j<tl[i];j++)
{
printf("%c",t[i][j]);
}
printf("\n");
}
///////////////////////////
}
///////////////////////////////////////////

Posted: Sat Sep 03, 2005 1:24 pm
by Krzysztof Duleba
Use code tag for code listings. Otherwise it's impossible to read it (no indentation) and smileys will appear making it hard to copy and compile loclally.

Posted: Sat Sep 03, 2005 3:08 pm
by chunyi81
There is one very obvious problem. I tried compiling your code problem 123 with gcc 2.95 (the version used by UVA OJ), and I am assuming you are posting C code,
I got the following compile errors:
p123.c: In function `main':
p123.c:116: parse error before `char'
p123.c:124: `tmp' undeclared (first use in this function)
p123.c:124: (Each undeclared identifier is reported only once
p123.c:124: for each function it appears in.)
p123.c:127: `temp' undeclared (first use in this function)
p123.c:63: warning: return type of `main' is not `int'

In both your codes I see two obvious problems: // is C++ style comments, gcc 2.95 compiler does not allow it. And also main should return int. Also UVA OJ gcc compiler might not like the strupr function. Hope this helps.

Posted: Sat Sep 03, 2005 5:49 pm
by Sakib
Hey guys thanks for help!
The problem was in the function "strupr( )" in p123. (ACC now)
but not clear abt p187.

Posted: Mon Sep 05, 2005 4:25 am
by Cytoplasm
Use Gcc and compile with flags -ansi -Wall -pedantic
This way, you will never see those Compile Errors

Problem #123 - WA using C++!!

Posted: Tue Oct 11, 2005 1:51 am
by AnGeLoSo
Hi!

I don't know why I get WA :( Help, plz!

This is my code:

[quote]#include <string>
#include <iostream>
#include <algorithm>
#include <cctype>
#include <stdlib.h>
using namespace std;

bool pertenece(string cadena, string* vector, int limite)
{
bool pertenece = false;

for (int i=0; i<limite; i++)
{
if (cadena == vector)
pertenece = true;
}
return pertenece;
}


int compare_function(const void *a, const void *b)
{
string *x = (string *)a;
string *y = (string *)b;

if (*x < *y) return -1;
if (*x > *y) return 1;
return 0;
}


void mostrarTitulo(string palabra, string cadena)
{
int pos = cadena.find(palabra, 0);


while (pos != string::npos)
{
if (cadena[pos + palabra.size()] == ' ') // tiene que ser la palabra completa!
{
// Ponemos la palabra en mayusculas
for (int i=pos; i < pos + palabra.size(); i++)
cadena = (char) toupper(cadena);

// Mostramos la cadena
cout << cadena << endl;

// Ponemos la palabra de nuevo en minusculas
for (int i=pos; i < pos + palabra.size(); i++)
cadena = (char) tolower(cadena);
}
pos = pos + palabra.size();
pos = cadena.find(palabra, pos);
}
}




int main()
{
string cadena;
string palabra;
string palabrasIgnorar[51];
string titulos[201];
string todo[10000];
int numPalabrasIgnorar;
int numTitulos;
int numTodo;
int pos;



// 1) Guardamos en un vector todas las palabras a ignorar
numPalabrasIgnorar = 0;
while (cin >> cadena && cadena != "::")
{
palabrasIgnorar[numPalabrasIgnorar] = cadena;
numPalabrasIgnorar++;
}

// 2) Leemos los t

problem 123. / i got compile error

Posted: Wed Feb 07, 2007 1:06 am
by Gaolious
when i use the VC 6 or gcc 3.4.4 (cygwin), i did'nt find the any erorrs

just, some warnings are found.

but, the result(submission status) in online-judge is compile error.


could you try to compile the following code ?

Code: Select all

 cut 

Posted: Wed Feb 07, 2007 11:22 am
by shamim
The online judge should send you an email explaining the reason for compile error. Please check the mails.
If you don't receive any mail with each submission, you have the option disabled. So edit your accounts' profile so that you receive the mails.

Oh my god!

Posted: Wed Feb 07, 2007 12:17 pm
by Gaolious
shamim wrote:The online judge should send you an email explaining the reason for compile error. Please check the mails.
If you don't receive any mail with each submission, you have the option disabled. So edit your accounts' profile so that you receive the mails.
oh my god !

i forget them. i was soooooooooooooo stupid .

thanks for your reply, it is so so happy that i can see the your reply


and, the error message is

Code: Select all

Here are the compiler error messages:

05317750_24.c: In function `struct _MYWORD_list_ * Add_MYWORD_at_next(_MYWORD_list_ *, char *, int)':
05317750_24.c:84: implicit declaration of function `int strdup(...)'
05317750_24.c:84: assignment to `char *' from `int' lacks a cast

I am also getting WA

Posted: Tue May 29, 2007 1:42 am
by soddy
I have tried for many test cases but not getting right answer....even for the test cases given above....i cant find the reason
can anyone give some more test cases for this problem

Posted: Tue May 29, 2007 1:58 am
by soddy
i got it right!!! AC now :D