留下做题痕迹
2024-08-20 13:58:00
发布于:广东
13阅读
0回复
0点赞
致敬传奇写法if else
还有continue
情况:,,,为初始值,以及正常情况的、或,确实挺多条件的
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,xs;
bool second=1;
scanf("%d",&n);
while(n>=0){
scanf("%d",&xs);
if(xs==0){
n--;
continue;
}
if(second){
if(abs(xs)==1){
if(xs>0)printf("x^%d",n);
else printf("-x^%d",n);
second=0;
n--;
continue;
}
printf("%dx^%d",xs,n);
second=0;
n--;
continue;
}
if(n==0){
if(xs>0)printf("+%d",xs);
else printf("%d",xs);
n--;
continue;
}
if(abs(xs)==1){
if(n==1){
if(xs<0)printf("-x");
else printf("+x");
n--;
continue;
}
if(xs>0)printf("+x^%d",n);
else printf("-x^%d",n);
n--;
continue;
}
if(n==1){
if(xs<0)printf("%dx",xs);
else printf("+%dx",xs);
n--;
continue;
}
if(xs>0)printf("+%dx^%d",xs,n);
else printf("%dx^%d",xs,n);
n--;
}
return 0;
}
这里空空如也
有帮助,赞一个