当前位置:网站首页>P1067 [noip2009 popularity group] polynomial output (difficult, pit)

P1067 [noip2009 popularity group] polynomial output (difficult, pit)

2022-07-07 23:40:00 Yuesi

Original link
 subject
 Insert picture description here
 Insert picture description here

More points to consider
First of all, we must fully understand the meaning of the question

  1. n Not the number of input data in the second row , But the coefficient of the highest term , The actual number of input data in the second line is n+1 individual ,n Coefficient of secondary term to coefficient of primary term + 1 Constant term
  2. Judge whether the coefficient is 0
    Whether the coefficient is plus or minus one
    x To the power of 1 when x The power of is not output , Only the output x
    In front of the integer coefficient except the first output number “+” Is it missing

Learn from the code

#include<bits/stdc++.h>
using namespace std;
int main(){
    
	int n;
	int ans[110];
	int x;
	int t=0;
	int k=0;
	scanf("%d",&n);
	if(n==0){
    
		scanf("%d",&x);
		printf("%d",x);
	}else if(n==1){
    
		scanf("%d",&x);
		if(x!=0){
    
			if(abs(x)==1){
    
				if(x<0){
    
					printf("-");
				}	
			}else{
    
				printf("%d",x);
			}
			printf("x");
			k++;
		}
		scanf("%d",&x);	
		if(x>0){
    
			printf("+");
		}
		if(x!=0){
    
			k++;
			printf("%d",x);
		} 
		if(k==0){
    
			printf("0");
		}
	}else{
    
		int l=n;
		for(int i=1;i<=n-1;i++){
    
			scanf("%d",&ans[i]);
			if(ans[i]!=0){
    
				if(t==1){
    
					t=2;
				}
				if(t==0){
    
					t=1;
				}
				k++;
				if(t==2){
    
					if(ans[i]>0){
    
						printf("+");
					}
				}
				if(ans[i]>1||ans[i]<-1){
    
					printf("%d",ans[i]);
					printf("x^%d",l);
				}else{
    
					if(ans[i]==-1){
    
						printf("-");
					}
					printf("x^%d",l);
				}
			}
			l--;		
		}	
		scanf("%d",&x);
		if(x!=0){
    
			k++;
			if(abs(x)==1){
    
				if(x<0){
    
					printf("-");
				}
				if(x==1){
    
					printf("+");
				}	
			}else{
    
				if(x>0){
    
					printf("+");
				}
				printf("%d",x);
			}
			printf("x");
		}
		scanf("%d",&x);	
		if(x>0){
    
			printf("+");
		}
		if(x!=0){
    
			k++;
			printf("%d",x);
		}
		if(k==0){
    
			printf("0");
		}	
	}
	return 0;
}

Data points of two sets of cards

99
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 100 1 8

99
-1 5 -4 -2 1 -5 3 4 -1 4 -5 -5 4 -1 3 2 -1 -2 3 -4 1 1 -5 -2 -1 2 1 -4 -1 -1 -2 -1 5 -3 4 1 2 2 2 -2 -1 3 -1 -2 0 5 -4 -3 -1 3 2 -5 -3 -3 -3 2 0 2 -3 1 5 0 2 -2 0 -3 -3 -3 -5 -4 -4 -3 3 1 1 2 2 -1 0 -5 -4 0 -3 -5 0 -2 -2 -2 4 -1 -1 2 -5 4 1 -5 2 1 4 -3

原网站

版权声明
本文为[Yuesi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130556374769.html