bnuoj 1057 函数
来源:互联网 发布:车载wince修改gps端口 编辑:程序博客网 时间:2024/06/03 15:47
这题让我做成这样,也是醉了,看来做题方法很重要,不然会很坑!!!
解法:字符串模拟!
#include<bits/stdc++.h>using namespace std;int main(){ int T; cin>>T; while(T--) { string str,s; cin>>str>>s; int op=str.find('='),len=str.size(); int op1=s.find('='),len1=s.size(),flag=0; string num; num=s.substr(op1+1,len1-op1); if(num[0]=='-') flag=1; string tmp; if(isdigit(str[op+1])||str[op+1]=='x') tmp+='+'; for(int i=op+1;i<len;i++) { if(str[i]=='x') { if(!isdigit(str[i-1])) { tmp+="1*"; tmp+=num; } else { tmp+='*'; tmp+=num; } } else tmp+=str[i]; } int len2=tmp.size(); long long sum=0; for(int i=0;i<len2;i++) { if(tmp[i]=='-') { i++; int n=0,f=0,m=0,zh=0,f2=0; while(i<len2&&isdigit(tmp[i])) { n=n*10+tmp[i]-'0'; i++; } if(tmp[i]=='*') { i++; if(flag) i++; while(i<len2&&isdigit(tmp[i])) { m=m*10+tmp[i]-'0'; i++; } if(flag) m=0-m; f2=1; } if(tmp[i]=='^') { i++; while(i<len2&&isdigit(tmp[i])) { zh=zh*10+tmp[i]-'0'; i++; } f=1; } if(f2) { if(f) sum-=n*pow(m,zh); else sum-=n*m; } else { if(f) sum-=pow(n,zh); else sum-=n; } i--; } else if(tmp[i]=='+') { i++; int n=0,f=0,m=0,zh=0,f2=0; while(i<len2&&isdigit(tmp[i])) { n=n*10+tmp[i]-'0'; i++; } if(tmp[i]=='*') { i++; if(flag) i++; while(i<len2&&isdigit(tmp[i])) { m=m*10+tmp[i]-'0'; i++; } if(flag) m=0-m; f2=1; } if(tmp[i]=='^') { i++; while(i<len2&&isdigit(tmp[i])) { zh=zh*10+tmp[i]-'0'; i++; } f=1; } if(f2) { if(f) sum+=n*pow(m,zh); else sum+=n*m; } else { if(f) sum+=pow(n,zh); else sum+=n; } i--; } } cout<<"f(x)="<<sum<<"\n"; } return 0;}
0 0
- bnuoj 1057 函数
- BNUOJ 1777
- BNUOJ 6242
- 四叉树 bnuoj
- BNUOJ 14519
- BNUOJ 8108
- BNUOJ 8108
- BNUOJ 26190 --------------- In Braille
- BNUOJ 3013 Ancient Keyboard
- BNUOJ 12884 kruskal+ext_lca
- BNUOJ 4304 硬币迷阵
- BNUOJ 3884 Hay Expenses
- BNUOJ 4138 Dizzy Cows
- BNUOJ 4156 Chocolate Buying
- BNUOJ 14280 Extra Krunch
- BNUOJ 14362 Election Time
- BNUOJ 3869 Buying Hay
- BNUOJ 4157 Chocolate Giving
- TextView 因为特殊字符(半角圆角等问题)在折行的时候各种不爽 ,不规则折行
- C#图片验证码制作,上传图片加水印,使用Drawing绘制
- 51nod oj 1072 威佐夫游戏 1185 威佐夫游戏 V2【威佐夫博奕】
- day10————python作业socket
- ftp命令常用用法示例
- bnuoj 1057 函数
- CSS外边距合并
- asp.net数据绑定判断字段值是否为空
- svn 二级域名无法ping通并且unknown host 时候
- hdoj1045 Fire Net(DFS)
- 生成/扫描二维码
- 图的深度遍历
- 求二维平面上共线最多的点数
- 正则表达式在性能测试中的应用