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. JavaScript编程基础

    一. 1 .JavaScript基础语法 注释: 1.单行注释: //单行注释 多行注释: /* *较长的多行 *注释 * */ 最好是针对某个功能来写注释 2. 语句 在JavaScript中,语句 ...

  2. ArcMap10.2 中制作符号库

    今天在发布地图服务时,发现地图中的3D符号没法用,出现”00013“错误,如下:

  3. PAT甲级——A1074 Reversing Linked List

    Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elem ...

  4. python数据类型初始1

    int: 1,2,3就是用于计算. bool:主要是用于判断,True,False str:用引号引起来的,'dsldgau','张三'.主要用于储存少量数据,进行操作 list(列表):[1,2,3 ...

  5. DOS常用命令详解

    DOS常用命令详解 dir 列文件名 deltree 删除目录树 cls 清屏 cd 改变当前目录 copy 拷贝文件 diskcopy 复制磁盘 del 删除文件 format 格式化磁盘 edit ...

  6. PKU OJ A Bug's life

    http://bailian.openjudge.cn/tm2018/G/ #include <iostream> #include <vector> #include < ...

  7. Leetcode515. Find Largest Value in Each Tree Row在每个树行中找最大值

    您需要在二叉树的每一行中找到最大的值. 示例: 输入: 1 / \ 3 2 / \ \ 5 3 9 输出: [1, 3, 9] class Solution { public: vector<i ...

  8. 11.Hibernate一对多关系

    创建JavaBean 一方: Customer private long cust_id; private String cust_name; private long cust_user_id; p ...

  9. Elasticsearch系列(一)--入门

    Elasticsearch基于Lucene构建的开源搜索引擎,Java编写,提供restful API,支持横向拓展,能够完成海量数据处理. 应用场景: 1.海量数据分析引擎 2.站内搜索引擎 3.数 ...

  10. 关于HTTP协议(转)

    HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送 ...