UVA392 模拟(多项式输出),水
2016-11-09 20:45
344 查看
1 题意,输入一个多项式,输出它。
2 分析。
注意模拟题思路和代码都要按部就班、步骤条理清晰,一个姿势过不了,如果觉得有更清晰的思路,就不要纠结过不了代码,而是换个姿势重新来一发。多想想题目边界、自己代码分类的边界、以及0和1等特殊情况。
3
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int maxn=10;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int f[maxn];
memset(f,0,sizeof(f));
while(~scanf("%d",&f[8])){
///ini
for(int i=7;i>=0;i--){
scanf("%d",&f[i]);
}
///print
int st=0;
for(int j=8;j>=0;j--){
if(f[j]!=0){
if(st==0){
st=1;
if(j!=0){
///.base_number:(底数)
if(f[j]==1) cout<<"";
else if(f[j]==-1) cout<<"-";
else cout<<f[j];
///.index:(指数)
if(j==1) cout<<"x";
else cout<<"x^"<<j;
}
else{
cout<<f[j];
}
}
else if(st==1){
if(j!=0){
///.base_number:
if(f[j]==1) cout<<" + ";
else if(f[j]==-1) cout<<" - ";
else if(f[j]>1) cout<<" + "<<f[j];
else if(f[j]<-1) cout<<" - "<<-1*f[j];
///.index:
if(j==1) cout<<"x";
else cout<<"x^"<<j;
}
else{
if(f[j]>0) cout<<" + "<<f[j];
else if(f[j]<0) cout<<" - "<<-1*f[j];
}
}
}
}
//cout<<endl; presentation error
if(st==0) cout<<"0"<<endl;
else cout<<endl;
memset(f,0,sizeof(f));
}
}
2 分析。
注意模拟题思路和代码都要按部就班、步骤条理清晰,一个姿势过不了,如果觉得有更清晰的思路,就不要纠结过不了代码,而是换个姿势重新来一发。多想想题目边界、自己代码分类的边界、以及0和1等特殊情况。
3
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int maxn=10;
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int f[maxn];
memset(f,0,sizeof(f));
while(~scanf("%d",&f[8])){
///ini
for(int i=7;i>=0;i--){
scanf("%d",&f[i]);
}
int st=0;
for(int j=8;j>=0;j--){
if(f[j]!=0){
if(st==0){
st=1;
if(j!=0){
///.base_number:(底数)
if(f[j]==1) cout<<"";
else if(f[j]==-1) cout<<"-";
else cout<<f[j];
///.index:(指数)
if(j==1) cout<<"x";
else cout<<"x^"<<j;
}
else{
cout<<f[j];
}
}
else if(st==1){
if(j!=0){
///.base_number:
if(f[j]==1) cout<<" + ";
else if(f[j]==-1) cout<<" - ";
else if(f[j]>1) cout<<" + "<<f[j];
else if(f[j]<-1) cout<<" - "<<-1*f[j];
///.index:
if(j==1) cout<<"x";
else cout<<"x^"<<j;
}
else{
if(f[j]>0) cout<<" + "<<f[j];
else if(f[j]<0) cout<<" - "<<-1*f[j];
}
}
}
}
//cout<<endl; presentation error
if(st==0) cout<<"0"<<endl;
else cout<<endl;
memset(f,0,sizeof(f));
}
}
相关文章推荐
- UVa 392 根据系数输出多项式
- [再次模拟]多项式输出
- 洛谷P1067 多项式输出(模拟)
- NOJ2106 6_多项式输出(模拟)
- 洛谷模拟多项式输出P1067
- 洛谷 P1067 多项式输出(恶心纯模拟)
- noip2009 多项式输出 (模拟)
- 洛谷 1067——多项式输出(简单的模拟)
- 普及练习场 简单的模拟 多项式输出
- 2018.2.28【 UVa - 227 】解题报告(紫书练习题,模拟,输出格式)
- 【洛谷】P1067 多项式输出【模拟】
- |洛谷|NOIP2009|模拟|P1067 多项式输出
- 【模拟】洛谷 P1067 多项式输出
- uva 1352 LA3401 - Colored Cubes(模拟,4级)
- UVA 514 - Rails && POJ 1363 (堆栈模拟)
- UVALive 3971 Assemble(模拟 + 二分)
- (1.1.7)UVA 10935 Throwing cards away I(直叙式模拟)
- UVa 10726 - Coco Monkey (数学 + 模拟)
- uva 122 小球下落 树的模拟
- (数组的应用三:多项式的表示与处理4.3.1)POJ 1555 Polynomial Showdown(多项式的输出)