http://acm.hdu.edu.cn/showproblem.php?pid=1296

随手练习

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
int n;
char s[];
ll Solve(string s,int i)
{
ll num=;
int l=i-;
int r=i+;
string s1="";
while(s[l]>=''&&s[l]<='')
{
s1+=s[l];
l--;
}
reverse(s1.begin(),s1.end());
ll ans=;
ll sum=;
int len=s1.length();
for(int j=; j<len; j++)
{
ans*=;
ans+=(s1[j]-'');
}
if(ans==){
ans=; }
if(s[r]=='^')
{
r++;
while(s[r]>=''&&s[r]<='')
{
sum*=;
sum+=(s[r]-'');
r++;
}
ll pos=n;
for(int j=; j<sum; j++)
{
pos*=n;
}
num+=pos*ans;
}
else
{
num+=ans*n;
}
i=r;
if(s[l]=='-')
{
num*=-;
}
return num;
}
int main()
{
while(~scanf("%d",&n))
{
ll x=;
scanf("%s",s);
int len=strlen(s);
if((s[]>=''&&s[]<='')||s[]=='X')
{
string s1="";
int i=;
int pos=;
int flag=;
for(i=; s[i]!='+'&&s[i]!='-'&&i<len; i++)
{
s1+=s[i];
if(s[i]=='X')
{
flag=;
pos=i;
}
}
if(flag)
{
x+=Solve(s1,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s1.length(); j++)
{
ans*=;
ans+=(s1[j]-'');
}
x+=ans;
}
for(int j=i; j<len;)
{
if(s[j]=='-'||s[j]=='+')
{
string s2="";
s2+=s[j];
j++;
int ans=;
while(s[j]!='-'&&s[j]!='+'&&j<len)
{
s2+=s[j];
ans++;
if(s[j]=='X')
{
pos=ans;
flag=;
}
//cout<<s[j]<<endl;
j++;
}
if(flag)
{
x+=Solve(s2,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s2.length(); j++)
{
ans*=;
ans+=(s2[j]-'');
}
if(s2[]=='-')
{
ans*=-;
}
x+=ans;
}
flag=;
}
}
cout<<x<<endl;
}
else
{
int flag=;
int pos=;
string s3="";
s3+=s[];
int i;
for(i=; s[i]!='-'&&s[i]!='+'&&i<len; i++)
{
s3+=s[i];
if(s[i]=='X')
{
flag=;
pos=i;
}
}
if(flag)
{
x+=Solve(s3,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s3.length(); j++)
{
ans*=;
ans+=(s3[j]-'');
}
if(s3[]=='-')
{
ans*=-;
}
x+=ans;
}
flag=;
for(int j=i; j<len;)
{
if(s[j]=='-'||s[j]=='+')
{
string s2="";
s2+=s[j];
j++;
int ans=;
while(s[j]!='-'&&s[j]!='+'&&j<len)
{
s2+=s[j];
ans++;
if(s[j]=='X')
{
pos=ans;
flag=;
}
//cout<<s[j]<<endl;
j++;
}
if(flag)
{
x+=Solve(s2,pos);
flag=;
}
else
{
ll ans=;
for(int j=; j<s2.length(); j++)
{
ans*=;
ans+=(s2[j]-'');
}
if(s2[]=='-')
{
ans*=-;
}
x+=ans;
}
flag=;
}
}
cout<<x<<endl;
}
}
return ;
}

HDU1296 Polynomial Problem的更多相关文章

  1. Polynomial Problem(hdu 1296 表达式求值)

    We have learned how to obtain the value of a polynomial when we were a middle school student. If f(x ...

  2. hdu 1296 Polynomial Problem(多项式模拟)

    Problem Description We have learned how to obtain the value of a polynomial when we were a middle sc ...

  3. FZU 2215 Simple Polynomial Problem(简单多项式问题)

    Description 题目描述 You are given an polynomial of x consisting of only addition marks, multiplication ...

  4. FZU2215 Simple Polynomial Problem(中缀表达求值)

    比赛时没做出这题太可惜了. 赛后才反应过来这就是个中缀表达式求值,数字栈存的不是数字而是多项式. 而且,中缀表达式求值很水的,几行就可以搞定. #include<cstdio> #incl ...

  5. 第六届福建省大学生程序设计竞赛(FZU2213—FZU2221)

    from:piaocoder Common Tangents(两圆之间的公公切线) 题目链接: http://acm.fzu.edu.cn/problem.php?pid=2213 解题思路: 告诉你 ...

  6. NOIp初赛题目整理

    NOIp初赛题目整理 这个 blog 用来整理扶苏准备第一轮 csp 时所做的与 csp 没 有 关 系 的历年 noip-J/S 初赛题目,记录了一些我从不知道的细碎知识点,还有一些憨憨题目,不定期 ...

  7. CF #296 (Div. 1) B. Clique Problem 贪心(构造)

    B. Clique Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. [codeforces 528]B. Clique Problem

    [codeforces 528]B. Clique Problem 试题描述 The clique problem is one of the most well-known NP-complete ...

  9. 周赛-Integration of Polynomial 分类: 比赛 2015-08-02 08:40 10人阅读 评论(0) 收藏

    Integration of Polynomial Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

随机推荐

  1. Android Studio 字体大小和背景色的设置

    豆绿色的RGB值:#C7EDCC 1.打开Android Studio——>Ctrl+Alt+s 或者 File——>Settings 2.在弹窗中选中“Colors&Fonts” ...

  2. jsp日期插件My97DatePicker 强大的日期控件 使用方便简单(转)

    本文属转载(希望对编程爱好者有所帮助)详情请访问官方网站 http://www.my97.net/dp/index.asp 一. 简介 1. 简介 目前的版本是:4.7 2. 注意事项 My97Dat ...

  3. storm源码剖析(1):storm脚本

    今天看了一下storm的命令行脚本${STORM_HOME}/bin/storm,现在将剖析过程整理一下,作为记录.注:使用的storm版本为0.8.0. ${STORM_HOME}/bin/stor ...

  4. codeforces 558A A. Lala Land and Apple Trees(水题)

    题目链接: A. Lala Land and Apple Trees time limit per test 1 second memory limit per test 256 megabytes ...

  5. drop asm disk、撤销drop asm disk

    drop asm disk.撤销drop asm disk drop asm disk:SQL> alter diskgroup XXX offline disk XXXX drop after ...

  6. WPF error: does not contain a static 'Main' method suitable for an entry point

    WPF error: does not contain a static &apos;Main&apos; method suitable for an entry point doe ...

  7. Jasper-template

    ylbtech-Jasper: 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbtech. ...

  8. Jasper:SAOP API 函数

    ylbtech-Jasper:SAOP API 函数 1.设备API返回顶部 1. 设备 设备 API 可以访问详细的设备(SIM 卡)信息,包括当前会话.您也可以更改属性值. API 调用 描述 A ...

  9. Jenkins远程执行shell出现java: command not found

    之前在使用Jenkins执行远程shell脚本时,出现提示java: command not found:多方查找原因后发现是因为远程执行shell脚本时,不会自动加载环境变量,导致出现此错误,解决方 ...

  10. 关于System类中out属性 实例化的问题

    System类中out属性的声明是这样的: public final static PrintStream out = nullPrintStream(); private static PrintS ...