But i m getting WA.Can anyone help?
Code: Select all
code deleted after got ac
Moderator: Board moderators
Code: Select all
code deleted after got ac
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));
}
}
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");
}
}
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
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;
}
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;
}
Code: Select all
istringstream iss;
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;
}
what is meant by "evaluating" here??plz help........For each pair of lines, your program should evaluate the polynomial for all the values of x