Page 1 of 6
Posted: Tue Jan 01, 2002 1:13 pm
by wyvmak
frustrated in WA. any tricks on that? will a test case takes more than one line? can anyone supply some tricky sample input?
Posted: Sun Jan 06, 2002 9:00 pm
by Adrian Kuegel
Test Input:
Fractal values for voltage U=1.111kV and current I=1.111kA are leading to what power?
Posted: Sat Jan 12, 2002 8:12 am
by wyvmak
so is the output 0.00W?
Posted: Sat Jan 12, 2002 10:53 am
by Ilham Kurnia
Nope.
P=1.00W
537
Posted: Thu Jul 04, 2002 5:57 pm
by htl
It alway gets WA. But I don't know where the bugs are.
[c]
#include<stdio.h>
#include<string.h>
#define YES 1
#define NO 0
void main(void)
{
int amp,volt,power,ampcnt,voltcnt,powercnt,n,x,y,point;
double temp,v,p,a,b;
char buffer[10000];
scanf("%d",&n);
for(x=0;x<n;x++)
{
fflush(stdin);
fgets(buffer,10000,stdin);
buffer[strlen(buffer)-1]='\0';
amp=volt=power=ampcnt=voltcnt=powercnt=point=NO;
for(y=0,temp=0;buffer[y]!='\0';y++)
{
if(buffer[y]=='I' && y<strlen(buffer)-1)
if(buffer[y+1]=='=')
ampcnt=amp=YES;
if(buffer[y]=='U' && y<strlen(buffer)-1)
if(buffer[y+1]=='=')
voltcnt=volt=YES;
if(buffer[y]=='P' && y<strlen(buffer)-1)
if(buffer[y+1]=='=')
powercnt=power=YES;
if(ampcnt)
if(buffer[y]>='0' && buffer[y]<='9')
{
temp=temp*10+buffer[y]-'0';
if(point)
temp/=10;
}
else if(buffer[y]=='m')
temp/=1000;
else if(buffer[y]=='k')
temp*=1000;
else if(buffer[y]=='M')
temp*=1000000;
else if(buffer[y]=='.')
point=YES;
else if(buffer[y]=='A')
{
a=temp;
temp=0;
ampcnt=NO;
point=NO;
}
if(voltcnt)
if(buffer[y]>='0' && buffer[y]<='9')
{
temp=temp*10+buffer[y]-'0';
if(point)
temp/=10;
}
else if(buffer[y]=='m')
temp/=1000;
else if(buffer[y]=='k')
temp*=1000;
else if(buffer[y]=='M')
temp*=1000000;
else if(buffer[y]=='.')
point=YES;
else if(buffer[y]=='V')
{
v=temp;
temp=0;
voltcnt=NO;
point=NO;
}
if(powercnt)
if(buffer[y]>='0' && buffer[y]<='9')
{
temp=temp*10+buffer[y]-'0';
if(point)
temp/=10;
}
else if(buffer[y]=='m')
temp/=1000;
else if(buffer[y]=='k')
temp*=1000;
else if(buffer[y]=='M')
temp*=1000000;
else if(buffer[y]=='.')
point=YES;
else if(buffer[y]=='W')
{
p=temp;
temp=0;
powercnt=NO;
point=NO;
}
}
printf("Problem #%d\n",x+1);
if(amp && volt)
printf("P=%.2lfW\n\n",a*v);
if(amp && power)
printf("U=%.2lfV\n\n",p/a);
if(volt && power)
printf("I=%.2lfA\n\n",p/v);
}
}
[/c]
Posted: Fri Jul 05, 2002 6:32 am
by htl
But my program replies "P=1690000.00W"
I think the answer should be 1111*1111=1234321
Maybe it's the accuracy problem.
Posted: Fri Jul 12, 2002 8:51 am
by Dominik Michniewski
Htl, you have right, answer in this case is 1234321
537 - Artificial Intelligence
Posted: Mon Jan 06, 2003 9:45 am
by mie
why do i always get the compile error report when i send my source code..?
Here are the compiler error messages:
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o: In function
`_start':
/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o(.text+0x18):
undefined reference to `main'
collect2: ld returned 1 exit status
does any one can help me plz? thx
Posted: Mon Jan 06, 2003 10:01 am
by Dominik Michniewski
are you sure, that your main function is called "main" (lower case) ?
Regrads
Dominik
PS. If you wish, try to send me your code, or put it here

) If you wish - cut unnecessary functions

))
emm..
Posted: Mon Jan 06, 2003 10:11 am
by mie
here are the source code..

plz help me thxxxx..
@begin_of_source_code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* @JUDGE_ID: 27057TE 537 C */
#define INPUTFILE "AI.IN"
#define OUTPUTFILE "AI.OUT"
FILE *finput;
FILE *foutput;
void main() {
char input[100];
char num[100];
char ch[2];
char f=0;
char finished=0;
int i,j;
double P,I,U;
char vp,vi,vu;
char *pv;
double *p;
int problem=0;
printf("Artificial Intelligence\n");
printf("=======================\n\n\n");
printf("Open input file %s...\n",INPUTFILE);
finput = fopen(INPUTFILE,"rt");
if (finput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");
printf("Open output file %s...\n",INPUTFILE);
foutput = fopen(OUTPUTFILE,"wt");
if (foutput == NULL) {
printf("Open File Fail.\n");
exit(EXIT_FAILURE);
}
printf("Open File Success.\n\n");
printf("Processing input file...\n");
input[0]='\0';
i=0;
f=0;
finished=0;
vi=vp=vi=0;
while (finished==0) {
if (fgets(ch,2,finput)==NULL) {
finished = 1;
}
if (ch[0] == ' ' || ch[0] == ',' || ch[0] == '\n' || (finished)) {
input
= '\0';
if (f==1 && strlen(input) > 0) {
printf("%s\n",input);
if (input[0]=='P') {
pv = &vp;
p = &P;
}else if (input[0] == 'U') {
pv = &vu;
p = &U;
}else {
pv = &vi;
p = &I;
}
*pv = 1;
for (i=0,j=0; i<strlen(input); i++) {
if (input >= '0' && input <= '9') {
num[j] = input;
j++;
}
}
num[j]='\0';
if (strlen(num)>0) { *p = strtod(num,NULL);
printf("P = %f, U = %f, I = %f\n",P,U,I);
}
}
if (ch[0] == '\n' || (finished)) {
problem++;
fprintf(foutput,"Problem #%d\n",problem);
if (vp == 0) {
P = U * I;
fprintf(foutput,"P = %lfW\n\n",P);
}else if (vu == 0) {
U = P / I;
fprintf(foutput,"U = %lfA\n\n",U);
}else {
I = P / U;
fprintf(foutput,"I = %lfV\n\n",I);
}
P=U=I=0;
vp=vu=vi=0;
}
i=-1;
f=0;
} else {
if (ch[0]=='=') {f=1;}
input=ch[0];
}
i++;
}
printf("Processing completed\n");
fclose(finput);
fclose(foutput);
}
@end_of_source_code
Posted: Mon Jan 06, 2003 10:18 am
by Dominik Michniewski
I think, that your problem is using fopen, fclose and some other input/output functions ....
This function are not allowed on OJ

Try to avoid it - read from standard input and write to standard output

)
if you want to test your progra under Dos/Windows/Unix run it in this way:
program_name <data.in >data.out
data.in, data.out - your name of files which you want to use to test solution

program_name - executable file name (example: 537.exe, a.out )
Try this
Dominik
Posted: Tue Jan 21, 2003 3:55 pm
by Shahriar Nirjon
You can try this. But..
3
I=-.002A. U=10V
I=.00A U=-0.00V
I=-1A U=2V

AC
Posted: Tue Jan 21, 2003 5:06 pm
by Shahriar Nirjon
I got AC now :
* input may be like: I=-1e-2A U=2e3V
* donot print minus zero ie, -0.00 : print 0.00

537 A.I pls help , I'm getting WA
Posted: Fri Feb 14, 2003 6:26 am
by deddy one
someone pls give me input test case for this problem
one more question ==> is P,U,and I always be in uppercase
or it can be written in lowercase too ????
Posted: Fri Feb 21, 2003 1:22 am
by deddy one
this is so frustrating, I already match your sample I/O but still got
WA