【openjudge 计算概论(A)】[ 函数与字符串练习(2)]
来源:互联网 发布:淘宝最牛卖家骂人 店名 编辑:程序博客网 时间:2024/04/30 09:40
1:单词翻转
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;char s[510];int len;int main(){ int i,last=0; gets(s); len=strlen(s); for (i=0;i<len;++i) if (s[i]==' ') { for (int j=i-1;j>=last;j--) printf("%c",s[j]); printf(" "); last=i+1;} for (i=len-1;i>=last;i--) printf("%c",s[i]); return 0;}2:DNA排序
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct fnd{char s[110];int tm,num,nm;}a[110];inline int tmp(fnd x,fnd y){ if (x.tm<y.tm) return 1; if (x.tm>y.tm) return 0; if (x.nm<y.nm) return 1; if (x.nm>y.nm) return 0;}int n,m;int main(){ int i,j,t; scanf("%d%d",&n,&m); for(t=1;t<=m;++t) { cin>>a[t].s; for (i=0;i<n;++i) for (j=i+1;j<n;++j) if (a[t].s[i]>a[t].s[j]) a[t].tm++; a[t].num=t; a[t].nm=t; } sort(a+1,a+m+1,tmp); for (i=1;i<=m;i++) printf("%s\n",a[i].s); return 0;}
3:角谷猜想
#include<cstdio>#include<cstring>#include<iostream>using namespace std;int x;void pract(int x){if(x==1) {printf("End\n"); return;}if (x%2) {int a=x*3+1; printf("%d*3+1=%d\n",x,a); pract(a);} else {int a=x/2; printf("%d/2=%d\n",x,a); pract(a);}return;}int main(){ scanf("%d",&x); pract(x); return 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;}
5:扩号匹配问题
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>using namespace std;int d[110],t,h[110],t1,len;char s[110];bool p[110];inline void init1(int x){d[++t]=x;}inline void init(int x){h[++t1]=x;}inline void pop(){ t--;}int main(){ while(scanf("%s",s)==1) { memset(d,0,sizeof(d)); memset(h,0,sizeof(h)); memset(p,0,sizeof(p)); len=strlen(s); t=0; t1=0; for (int i=0;i<len;++i) { if (s[i]=='(') init1(i+1); if (s[i]==')'&&t) pop(); else if (s[i]==')'&&!t) init(i+1); } cout<<s<<endl; for(int i=t+1;i<=t+t1;++i) d[i]=h[i-t],p[h[i-t]]=1; t+=t1; sort(d+1,d+t+1); int last=0; for(int i=1;i<=t;++i) { for (int j=1;j<d[i]-last;++j) printf(" "); last=d[i]; if (p[d[i]]) printf("?"); else printf("$"); } printf("\n"); } return 0;}
0 0
- 【openjudge 计算概论(A)】[ 函数与字符串练习(2)]
- 【openjudge 计算概论(A)】[函数与字符串练习(1)]
- 【openjudge 计算概论(A)】[函数递归练习(2)]
- openjudge 计算概论 函数与字符串练习(1)2:字符串排序
- 【openjudge 计算概论(A)】[编程练习(字符串)]
- 【openjudge 计算概论(A)】[函数递归练习(4)]
- 【openjudge 计算概论(A)】[函数递归练习(3)]
- 【openjudge 计算概论(A)】[函数递归练习(1)]
- 【openjudge 计算概论(A)】[指针练习]
- 【openjudge 计算概论(A)】[基础编程练习2]
- 【openjudge 计算概论(A)】[编程练习(数组练习)]
- 计算概论(A) / 函数与字符串练习(2)2:DNA排序
- 【openjudge 计算概论(A)】[基础编程练习1]
- 【openjudge 计算概论(A)】[结构体与链表练习]
- 【openjudge 计算概论(A)】[基础编程练习(控制成分)]
- 【openjudge 计算概论(A)】[基础编程练习(运算成分)]
- 【openjudge 计算概论(A)】[基础编程练习(数据成分)]
- openjudge 计算概论基础编程练习(控制成分)
- C++指针和const 限定符
- 基于ARM的智能灯光控制系统(5)设备链表
- iOS客户端校验https网络请求证书
- 基于WebRTC实现页面浏览器视频通话-原理及实现demo
- SourceTree的使用
- 【openjudge 计算概论(A)】[ 函数与字符串练习(2)]
- 牛客网刷题之整数中1出现的次数(从1到n整数中1出现的次数)
- Bluedroid L2CAP 链路限制总结
- GIT里程碑
- 测试驱动开发搜集
- XMLHttpRequest对象及其使用
- volley
- MySQL GRANT REVOKE用法
- 第八周项目1-建立顺序串算法库