Page 4 of 5
498-why WA
Posted: Mon Jun 19, 2006 2:37 pm
by sohag144
I checked all i/o that i got from previous topic.
But i m getting WA.Can anyone help?
Posted: Tue Jun 20, 2006 9:22 pm
by the LA-Z-BOy
char word[MAX][10];
seems too small here... get something like
char word[MAX][20];
Also you would get
Presentation Error on this, because you are printing extra space at end of each line.
Greetings.
Posted: Sun Jul 02, 2006 8:33 pm
by sohag144
Thank you again.
You help me a lot.got AC.
Posted: Wed Nov 08, 2006 5:21 am
by ALEXANDRIA_2
I can't understand why I keep gettin WA all the time...
can anyone tell me what's wrong with my code...
Code: Select all
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
long int A[100];
long int B[100];
int in;
int tes(char line[],int w){
long int i,len,isneg=1,f=0,sum=0,T;
in=0;
len=strlen(line);
for(i=0;i<len;i++)
{
if(line[i]=='-') isneg=0;
else
if(line[i]!=' ')
{
f=1;
T=line[i]-'0';
sum*=10;
sum+=T;
}
else
{
if(f)
{
if(!isneg) sum*=-1;
if(!w)A[in]=sum;
else B[in]=sum;
sum=0;
in++;
isneg=1;
f=0;
}
}
}
if(!isneg) sum*=-1;
if(!w)A[in]=sum;
else B[in]=sum;
in++;
return in;
}
long int sum(long int angka,long int pang){
int i;
if(!pang) return 1;
for(i=1;i<pang;i++)
{
angka*=angka;
}
return angka;
}
void main(){
char line[128];
int m,n;
long int T=0,X,Angka,k,pang,i,t=0,ctr=0;
while(gets(line))
{
if(ctr) printf("\n");
else ctr=1;
t=0;
m=tes(line,0);
gets(line);
n=tes(line,1);
for(k=0;k<n;k++)
{
Angka=B[k];
pang=m-1;
for(i=0;i<m;i++)
{
X=sum(Angka,pang);
X*=A[i];
T+=X;
pang--;
}
if(!t) {printf("%ld",T);t=1;}
else printf(" %ld",T);
T=0;
}
T=in=0;
memset(A,0,sizeof(A));
memset(B,0,sizeof(B));
}
}
I've passed all the input given in this thread..
and the output is correct....
Thanks...
How to get even number line input???(498,10268)
Posted: Sun Jan 07, 2007 8:48 pm
by S.M.ferdous
Hello to all
I have solved 498 problem but my problem in getting input.
I am not understanding how to accept an even number of lines of text.
Another puzzling matter is that I can't correctly implement the breaking condition.
I need some help.plz help me.

Posted: Thu Jan 11, 2007 7:41 am
by loghiyan
Try this way. It might do the trick ( haven't seen the problem statement :-p) :
Code: Select all
char line1[200],line2[200];
int n;
char *c,*d;
while (gets(line1) && gets(line2)){
c=strtok(line1," \n");
while (c){
n=atoi(c);
cout<<n<<endl;
c=strtok(NULL," \n");
}
d=strtok(line2," \n");
while (d){
n=atoi(d);
cout<<n<<endl;
d=strtok(NULL," \n");
}
}
Hope that helps.
Posted: Thu May 17, 2007 9:06 pm
by Freyr
Yeah, does anyone have any tricky test data for this? I've made loads of different possible problems, and my program solves them all, but still gets WA.
*shrugs*
Posted: Tue May 22, 2007 10:56 pm
by Freyr
Nevermind, it was a presentation error, but it came up as wrong answer.
For anyone else who may need test data...
Code: Select all
-1 1 -11 1 -1
1 -1 11 -11
45 0 23 0 21
500 2333 3213 1
Code: Select all
-11 -15 -14631 -17315
2812505750021 1333126955170913 4795737875394753 89
Double works.
Edit: Removed certain test cases as they don't appear in the judge's input file.
498 TLE ! Need Help
Posted: Sun Jul 22, 2007 11:25 am
by Freeman
I don't know if it's because of
cin.getline
My Sample Output is correct.
This is my code (a bit long):
Code: Select all
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main()
{
int i,k,len,ct,now;
int a[10000],b[10000],neg,xd=0;
char z[10000],zx[10000];
double sum,total;
while( cin.getline(z,10000) )
{
ct=0; total=0; neg=0; now=0;
len = strlen(z);
for (i=len-1;i>=0;i--)
{
if (z[i]>=48 && z[i]<=57)
{
total += int ( (z[i]-48)*pow(10.0,ct) );
ct++;
}
else if (z[i]=='-')
total *= -1;
if (z[i]==' ' || i==0)
{
a[now] = int(total);
xd++; // control of XD
ct=0;
total=0;
neg=0;
now++;
}
} //for
// cout << a[0] << " " << a[1] << " " << a[2] << endl;
int test=0;
now=0; total=0; neg=1; ct=0; sum=0;// neg 1 = + -1= -
cin.getline(zx,10000);
len = strlen(zx);
for (k=len-1;k>=0;k--)
{
if (zx[k]=='-')
total *= -1;
else if (zx[k]>=48 && zx[k]<=57)
{
total += (zx[k]-48)*pow(10.0,ct);
// cout << "total=" << total << endl;
ct++;
}
if (zx[k]==' ' || k==0)
{
for(i=0;i<xd;i++)
{
sum += a[i]*pow( total,i );
// cout << "sum=" << sum << endl;
}
b[test]=sum;
sum=0;
total=0;
now++;
ct=0;
test++;
if (zx[k]==10)
break;
}
} // for
for (i=test-1;i>=0;i--)
{
cout << b[i];
if (i!=0)
cout << " ";
}
cout << endl;
} //while
return 0;
}
Can someone tell me what's wrong with it? Thks.
Posted: Sun Jul 22, 2007 12:08 pm
by Jan
Dont open a new thread if one already exists. Use existing thread.
Wrong answer
Posted: Tue Dec 04, 2007 3:07 am
by vkubushyn
Hey, my code for this problem seems impeccable to me, and it's solved all the examples on this forum correctly, and yet I still get WA. Can anyone tell me what's wrong with my code? I tried printing a space after each line, not printing an ending blank line, and other possible PE problems... Thanks.
Code: Select all
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <iomanip>
#include <sstream>
using namespace std;
int main() {
cout << fixed << setprecision(0);
vector<double> coeff;
string s;
stringstream* sin;
double n, count, sum;
getline(cin, s);
while(!cin.eof()) {
sin = new stringstream(s);
while(*sin >> n)
coeff.push_back(n);
getline(cin, s);
if(!cin.eof()) {
sin = new stringstream(s);
*sin >> n;
while((*sin).good()) {
sum = 0; count = 0;
for(int i = coeff.size()-1; i >= 0; i--) {
sum += coeff[i]*pow(n, count);
count++;
}
cout << sum << " ";
*sin >> n;
}
coeff.clear();
getline(cin, s);
cout << endl;
}
}
return 0;
}
Posted: Tue Dec 04, 2007 9:02 am
by jjtse
Does anyone know if there's a limit on 'n' and 'm'?
Posted: Fri Dec 21, 2007 11:34 am
by Samiul
1000 will be enough for both n and m.
istringstream works !!!!
Posted: Fri Jan 18, 2008 5:51 am
by thomas1016
part of my code
I finally got AC
istringstream works !!!!
thanks a lot
Code: Select all
#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int pol(int,string);
void polf(string,string);
int main(){
int j,sum;
string po,k;
while(1){
if (!getline(cin,po)) break;
if (!getline(cin,k)) break;
polf(k,po);
}
//system("pause");
return 0;
}
Re: 498 TLE
Posted: Thu Jul 17, 2008 4:27 pm
by maruf
For each pair of lines, your program should evaluate the polynomial for all the values of x
what is meant by "evaluating" here??plz help........