【openjudge 计算概论(A)】[函数递归练习(1)]
来源:互联网 发布:淘宝开店认证在哪里 编辑:程序博客网 时间:2024/04/30 12:35
1:数组逆序重放
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[110],n;int main(){int i;scanf("%d",&n);for(i=1;i<=n;++i) scanf("%d",&a[i]);for(i=n;i>0;--i) printf("%d ",a[i]);return 0;}
2:逆波兰表达式
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;char s[1010][10];double d[1010];int td,t;double do1(double a,double b,char c1){if (c1=='+') return a+b;if (c1=='-') return a-b;if (c1=='*') return a*b;if (c1=='/') return a/b;return 0;}int main(){int i;while (cin>>s[++t]);t--;while (t>0) { if (s[t][0]>='0'&&s[t][0]<='9') { d[++td]=atof(s[t]); t--; } else { double x; x=do1(d[td],d[td-1],s[t][0]); td--; d[td]=x; t--; } }printf("%lf\n",d[1]);return 0; }
3:放苹果
#include<cstdio>#include<cstring>using namespace std;int f[15][15],n,m,t;int main(){int i,j,k;scanf("%d",&t);for (k=1;k<=t;k++) { scanf("%d%d",&n,&m); f[0][0]=1; for (i=1;i<=n;i++) for (j=1;j<=m;j++) if (i>=j) f[i][j]=f[i-1][j-1]+f[i-j][j]; for (i=1;i<m;i++) f[n][m]+=f[n][i]; printf("%d\n",f[n][m]); memset(f,0,sizeof(0)); }}
4:排队游戏
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct chuan{ int x,op;}a[110];int top,len;char s[110],c;int main(){ int i; scanf("%s",s); len=strlen(s); c=s[0]; for (i=0;i<len;++i) { if (s[i]==c) a[++top].x=i,a[top].op=1; else { if(a[top].op==1) printf("%d %d\n",a[top--].x,i); else a[++top].op=2,a[top].x=i; } } return 0;}
#include<cstdio>#include<algorithm>using namespace std;char ch[70];int a[70],n,ans;int find(int l,int r){if(l==r) return a[l];int sum=0;for(int i=l;i<r;++i) if(ch[i]=='+') sum=max(sum,find(l,i)+find(i+1,r)); else if(ch[i]=='*') sum=max(sum,find(l,i)*find(i+1,r));return sum;}int main(){int i;scanf("%d",&n);for(i=1;i<=n;++i) scanf("%d %c",&a[i],&ch[i]),a[n+i]=a[i],ch[n+i]=ch[i];for(i=1;i<=n;++i) ans=max(ans,find(i,i+n-1));printf("%d\n",ans);return 0;}
0 0
- 【openjudge 计算概论(A)】[函数递归练习(1)]
- 【openjudge 计算概论(A)】[函数递归练习(4)]
- 【openjudge 计算概论(A)】[函数递归练习(3)]
- 【openjudge 计算概论(A)】[函数递归练习(2)]
- 【openjudge 计算概论(A)】[指针练习]
- 【openjudge 计算概论(A)】[基础编程练习1]
- 【openjudge 计算概论(A)】[函数与字符串练习(1)]
- 【openjudge 计算概论(A)】[编程练习(数组练习)]
- 【openjudge 计算概论(A)】[编程练习(字符串)]
- 【openjudge 计算概论(A)】[基础编程练习2]
- 【openjudge 计算概论(A)】[ 函数与字符串练习(2)]
- openjudge 计算概论 函数与字符串练习(1)2:字符串排序
- 【openjudge 计算概论(A)】[基础编程练习(控制成分)]
- 【openjudge 计算概论(A)】[基础编程练习(运算成分)]
- 【openjudge 计算概论(A)】[基础编程练习(数据成分)]
- 【openjudge 计算概论(A)】[结构体与链表练习]
- openjudge 计算概论基础编程练习(控制成分)
- openjudge 计算概论-数组练习-错误侦测
- 关于修改 AchartEngine 源码的修改
- 第八周项目2—数据结构之自建算法库—链串
- android6.0动态获取权限
- 静态库和动态库
- String的== 和equals 比较
- 【openjudge 计算概论(A)】[函数递归练习(1)]
- Linux shell 中显示vim所打开的文件名方法
- eclipse+ADT 进行android应用签名打包详解
- 【初学笔记】数据库范式
- sudo apachectl -k stop & sudo apachectl -k start 常见错误
- Ubuntu LTS 系统学习使用体会和实用工具软件汇总 6.04 8.04 10.04 12.04 14.04 16.04
- 网络通讯类的逆向
- Linlayout垂直布局如何让view下面居底
- 第八周 项目一 建立顺序串的算法库