Problem Type : Number Theroy
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int a[9000],b,i;
while(scanf("%d",&a[0])!=EOF){
for(i=1;i<9;i++)
scanf("%d",&a[i]);
b=0;
for(i=0;i<7;i++){
if(b==0){
if (a[i]>1){
printf("%dx^%d",a[i],8-i);
b=1;
}
else if(a[i]<-1){
printf("%dx^%d",a[i],8-i);
b=1; }
else if(a[i]==1){
printf("x^%d",8-i);
b=1;}
else if(a[i]==-1){
printf("-x^%d",8-i);
b=1;} }
else{
if (a[i]>1)
printf(" + %dx^%d",a[i],8-i);
else if(a[i]<-1){
a[i]*=-1;
printf(" - %dx^%d",a[i],8-i);
}
else if(a[i]==1)
printf(" + x^%d",8-i);
else if(a[i]==-1)
printf(" - x^%d",8-i);
} }
if(b==0){
if(a[7]>1){
printf("%dx",a[7]);
b=1; }
else if(a[7]<-1){
printf("%dx",a[7]);
b=1; }
else if(a[7]==1){
printf("x");
b=1;}
else if(a[7]==-1){
printf("-x");
b=1;}}
else{
if(a[7]>1)
printf(" + %dx",a[7]);
else if(a[7]<-1){
a[i]*=-1;
printf(" - %dx",a[7]);}
else if(a[7]==1)
printf(" + x");
else if(a[7]==-1)
printf(" - x");}
if(b==0){
if(a[8]>1)
printf("%d",a[8]);
else if(a[8]<-1){
printf("%d",a[8]);}
else if(a[8]==1)
printf("1");
else if(a[8]==-1)
printf("-1");
else
printf("0");
}
else{
if(a[8]>1)
printf(" + %d",a[8]);
else if(a[8]<-1){
a[8]*=-1;
printf(" - %d",a[8]);}
else if(a[8]==1)
printf(" + 1");
else if(a[8]==-1)
printf(" - 1");
}
printf("\n");
}
return(0);
}
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int a[9000],b,i;
while(scanf("%d",&a[0])!=EOF){
for(i=1;i<9;i++)
scanf("%d",&a[i]);
b=0;
for(i=0;i<7;i++){
if(b==0){
if (a[i]>1){
printf("%dx^%d",a[i],8-i);
b=1;
}
else if(a[i]<-1){
printf("%dx^%d",a[i],8-i);
b=1; }
else if(a[i]==1){
printf("x^%d",8-i);
b=1;}
else if(a[i]==-1){
printf("-x^%d",8-i);
b=1;} }
else{
if (a[i]>1)
printf(" + %dx^%d",a[i],8-i);
else if(a[i]<-1){
a[i]*=-1;
printf(" - %dx^%d",a[i],8-i);
}
else if(a[i]==1)
printf(" + x^%d",8-i);
else if(a[i]==-1)
printf(" - x^%d",8-i);
} }
if(b==0){
if(a[7]>1){
printf("%dx",a[7]);
b=1; }
else if(a[7]<-1){
printf("%dx",a[7]);
b=1; }
else if(a[7]==1){
printf("x");
b=1;}
else if(a[7]==-1){
printf("-x");
b=1;}}
else{
if(a[7]>1)
printf(" + %dx",a[7]);
else if(a[7]<-1){
a[i]*=-1;
printf(" - %dx",a[7]);}
else if(a[7]==1)
printf(" + x");
else if(a[7]==-1)
printf(" - x");}
if(b==0){
if(a[8]>1)
printf("%d",a[8]);
else if(a[8]<-1){
printf("%d",a[8]);}
else if(a[8]==1)
printf("1");
else if(a[8]==-1)
printf("-1");
else
printf("0");
}
else{
if(a[8]>1)
printf(" + %d",a[8]);
else if(a[8]<-1){
a[8]*=-1;
printf(" - %d",a[8]);}
else if(a[8]==1)
printf(" + 1");
else if(a[8]==-1)
printf(" - 1");
}
printf("\n");
}
return(0);
}
No comments:
Post a Comment