九度oj 1199 找位置
来源:互联网 发布:40本网络禁书txt 编辑:程序博客网 时间:2024/05/18 00:30
对给定的一个字符串s,找出有重复的字符,并给出其位置,如:abcaaAB12ab12
输出:a,0;a,3;a,4;a,9,b,1;b,10,1,7;1,11, 2,8;2,12。
思路:用一个数组tag[]把相同的字符连接起来 , 例如:tag[]=3 10 2 4 9 5 6 11 12 9 10 11 12
用数组v[]来标识s[]是否被访问过,
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){ char s[110]; int tag[110],vis[110],v[110]; while(scanf("%s",s)==1) { int n=strlen(s); for(int i=0;i<n;i++) { tag[i]=i; vis[i]=0; v[i]=0; } for(int i=0;i<n-1;i++) { int temp=i; for(int j=i+1;j<n;j++) { ///if(s[j]==s[i] && tag[j]==j) /** 不能用tag[j]==j来判断s[j]是否被串起来了 因为最后一个最是满足tag[j]==j的条件 */ if(s[j]==s[i]&&v[j]==0) { tag[temp]=j; temp=j; v[j]=1; } } } for(int i=0;i<n-1;i++) { if(tag[i]!=i && vis[i]==0) { printf("%c:%d",s[i],i); int temp=i; while(tag[temp]!=temp) { vis[temp]=1; printf(",%c:%d",s[i],tag[temp]); temp=tag[temp]; } printf("\n"); } } } return 0;}
0 0
- 九度OJ 题目1199:找位置
- 九度oj 1199 找位置
- 【九度OJ】1199:找位置
- 九度OJ 1199:找位置 (计数)
- 【九度OJ】题目1199:找位置 解题报告
- 九度-1199 找位置(链表)
- 九度OJ 1052 找x
- 九度OJ 1052 找x
- 九度OJ 1170 找最小数
- 九度OJ题目1052:找x
- 九度 OJ 1170:找最小数
- 九度 OJ 1052:找x
- 九度OJ题目1052:找x
- 九度OJ 题目1170:找最小数
- 九度OJ—题目1052:找x
- 九度OJ 1052:找x (基础题)
- 九度OJ 1170:找最小数 (最值)
- 【九度OJ】题目1052:找x 解题报告
- ForkJoin-任务分拆合并处理器
- 南宁SEO教你怎么做文章类站点的外链建设
- The 3rd day learning Java
- dfdsfdsf
- javascript 正则表达式
- 九度oj 1199 找位置
- 个人笔记 进程 线程 程序 区别
- Basic Debugging
- smack 源码分析一(android上实现长连接)
- smack 源码分析- PacketWriter (android上实现长连接)
- OpenStreetMap初探(一)——了解OpenStreetMap
- smack 源码分析- PacketReader (android上实现长连接)
- 第17章 创建图形用户界面
- 异步消息的传递之回调机制