Problem Description 
We have learned how to obtain the value of a polynomial when we were a middle school student. If f(x) is a polynomial of degree n, we can let.If we have x, we can get f(x) easily. But a computer can not understand the expression like above. So we had better make a program to obtain f(x).

Input 
There are multiple cases in this problem and ended by the EOF. In each case, there are two lines. One is an integer means x (0<=x<=10000), the other is an expression means f(x). All coefficients ai(0<=i<=n,1<=n<=10,-10000<=ai<=10000) are integers. A correct expression maybe likes  1003X^5+234X^4-12X^3-2X^2+987X-1000

Output 
For each test case, there is only one integer means the value of f(x).

Sample Input 

1003X^5+234X^4-12X^3-2X^2+987X-1000

Sample Output 
264302

Notice that the writing habit of polynomial f(x) is usual such as 
X^6+2X^5+3X^4+4X^3+5X^2+6X+7 
-X^7-5X^6+3X^5-5X^4+20X^3+2X^2+3X+9 
X+1 
X^3+1 
X^3 
-X+1 etc. Any results of middle process are in the range from -1000000000 to 1000000000.

自己写的超丑,查了一年的bug,最后发现是多组数据而我只写了一组.........哭了

 #include <iostream>
#include <cstdio>
#include <string.h>
#include <math.h>
#include <algorithm>
#define MIN(x,y) ((x)>(y))?(y):(x)
#define MAX(x,y) ((x)>(y))?(x):(y) using namespace std; const int inf = 0x3f3f3f3f;
const double dinf = 0xffffffff;
const int vspot = ;
const int espot = ;
typedef long long ll; int bit[];
int x, weishu, cnt;
ll ans;
int bound;
bool e;
bool positive; long long getNum()
{
if( !weishu )
{
if(positive)
return ;
else
return -;
} ll num = ;
int k = weishu;
for( int i = ; i < k; i++ )
{
weishu--;
ll zhishu = ;
for( int j = ; j < weishu; j++ )
zhishu *= ;
num += (long long)(bit[i]*zhishu);
} if(positive)
return num;
else
return -num;
} bool check()
{
if ( cnt == bound )
return true;
return false;
} int main()
{ while( cin >> x )
{
string ads, str = "+";
cin >> ads; cnt = ;
e = false;
ans = ; if ( ads[]=='-' )
str = ads;
else
str += ads; bound = str.size() - ; while(true)
{
////////////////////符号部分////////////////////
if ( str[cnt++]=='+' )
positive = true;
else
positive = false; //////////////////////因数ai部分///////////////////
weishu = ;
memset( bit, -, sizeof(bit) );
while(true)
{
if ( str[cnt]>='' && str[cnt]<='' )
{
if ( check() )
{
e = true;
bit[weishu++] = str[cnt]-'';
ans += getNum();
break;
}
else
bit[weishu++] = str[cnt++]-'';
}
else
break;
}
if (e)
break;
//////////////X^x部分//////////////////////
ll ai = getNum();
int cishu = ;
if( check() )
e = true;
else
{
if ( str[cnt+] == '^' )
{
cnt++; cnt++;
if ( str[cnt]>='' && str[cnt]<='' )
cishu = str[cnt]-'';
else
{ cishu = ; cnt++;}
}
}
if ( check() )
e = true;
else
cnt++;
//////////////计算部分/////////////////////////
ll temp = ;
for( int i = ; i < cishu; i++ )
temp *= x;
ans += ai*temp;
if (e)
break;
}
cout << ans << endl;
}
return ;
}

再看看 别人写的.........我............我好菜呀QAQ

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int const nMax = ;
#define sf scanf
#define pf printf
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
char s[nMax];
int x;
#define ll long long
ll go(int &i)
{
int a,b,c;
a = ;
b = ;
if(s[i] == '-') a*=-,i++;
if(s[i] == '+') i++;
while(s[i]>='' && s[i]<='')
{
b = b* + s[i]-'';
i++;
}
if(b==) b = ;//这句就是应证X+1
c = ;
if(s[i] == 'X')
{
i++;
if(s[i]=='^')
{
i++; c = ;
while(s[i]>='' && s[i]<='')
{
c = c* + s[i] - '';
i ++;
}
}
else
{
c = ;
}
}
ll ret = ;
ret = (ll)a*b;
for(int i=; i<c; i++) ret *= x;
return ret;
}
int main()
{
while(cin >> x >> s)
{
int i = ;
int l = strlen(s);
ll ans = ;
while(i<l)
{
ans += go(i);
}
cout << ans << endl;
}
return ;
}

hdu 1296 Polynomial Problem(多项式模拟)的更多相关文章

  1. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  2. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  3. HDOJ/HDU 1022 Train Problem I(模拟栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  4. HDU 1022 Train Problem I 模拟栈题解

    火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...

  5. HDU 5867 Water problem ——(模拟,水题)

    我发这题只是想说明:有时候确实需要用水题来找找自信的~ 代码如下: #include <stdio.h> #include <algorithm> #include <s ...

  6. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  7. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  8. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  9. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

随机推荐

  1. Zuul的过滤器

    过滤器类型与请求生命周期:         Zuul中定义了4种标准过滤器类型,这些过滤器类型对应于请求的典型生命周期         PRE: 这种过滤器在请求被路由之前调用.可利用这种过滤器实现身 ...

  2. Java-MyBatis-MyBatis3-XML映射文件:select

    ylbtech-Java-MyBatis-MyBatis3-XML映射文件:select 1.返回顶部 1. select 查询语句是 MyBatis 中最常用的元素之一,光能把数据存到数据库中价值并 ...

  3. H-ui 前端框架

    H-ui 前端框架 架起设计与后端的桥梁轻量级前端框架,简单免费,兼容性好,服务中国网站. 首个付费版产品 H-ui.admin.Pro,盘他!

  4. 一次读懂mybatis中的缓存机制

    缓存功能针对于查询(没听说果UPDATE,INSERT语句要缓存什么,都是直接执行的) 默认情况下,mybatis会启用一级缓存. 如果使用同一个session对象调用了相同的SELECT语句,则直接 ...

  5. spring boot 项目添加maven依赖时provided

    spring boot 项目是自带tomcat 的,但是我们有时候是需要把项目打包成war 然后放到独立的tomcat中运行的,这个时候我们就需要将它自带的tomcat给排除开,这时候我们就可以使用& ...

  6. HBase 数据坐标

  7. Exit- Linux必学的60个命令

    1.作用 exit命令的作用是退出系统,它的使用权限是所有用户. 2.格式 exit 3.参数 exit命令没有参数,运行后退出系统进入登录界面.

  8. csp-s模拟测试53u,v,w题解

    题面:https://www.cnblogs.com/Juve/articles/11602450.html u: 用差分优化修改 二维差分:给(x1,y1),(x2,y2)加上s: $d[x1][y ...

  9. Laravel 错误处理

    错误提示:cURL error 60: SSL certificate problem: unable to get local issuer certificate 解决方案:修改文件,重启队列即可 ...

  10. Pycharm中运行Python代码的几种方式

    在pycharm中的Python代码运行会出现各种奇葩的问题,比如,密码输入时不显示或没有提示,给我们带来一些麻烦,下面介绍几种代码运行的几种方式: 一.直接运行(Run按钮或者快捷键shift+F1 ...