123 - Searching Quickly
Moderator: Board moderators
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.
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.
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
Thank you any way.
I stay home. Don't call me out.
compile error in 187 and 123 plz heeeeeeeelp!!
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");
}
///////////////////////////
}
///////////////////////////////////////////
// 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");
}
///////////////////////////
}
///////////////////////////////////////////
/* Sorry For Nothing */
- Krzysztof Duleba
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
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.
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.
Problem #123 - WA using C++!!
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
I don't know why I get WA

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
-
- New poster
- Posts: 28
- Joined: Mon Nov 04, 2002 8:03 pm
- Location: South Korea, Seoul
- Contact:
problem 123. / i got compile error
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 ?
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
Last edited by Gaolious on Wed Feb 07, 2007 3:05 pm, edited 1 time in total.
-
- New poster
- Posts: 28
- Joined: Mon Nov 04, 2002 8:03 pm
- Location: South Korea, Seoul
- Contact:
Oh my god!
oh my god !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.
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
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
can anyone give some more test cases for this problem