GYM 100090 G.The Last Wish(水~)
来源:互联网 发布:车道识别算法 编辑:程序博客网 时间:2024/04/29 13:44
Description
给出一个长度为n的字符串,对于重复出现的字符,要把其转化为字符串中尚未出现的最小字母,问是否可以将这个字符串变成每个字母都不同的串
Input
一个只有小写字母字符串,串长不超过200000
Output
如果可以转化则输出转化后的结果,否则输出IMPOSSIBLE
Sample Input
abcba
Sample Output
abcde
Solution
简单题,长度超过26肯定不行,否则可以,对于重复字符枚举没出现的字符给其赋值即可
Code
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>#include<vector>#include<queue>#include<map>#include<set>#include<ctime>using namespace std;typedef long long ll;#define INF 0x3f3f3f3f#define maxn 222222char s[maxn];int main(){ while(~scanf("%s",s)) { int n=strlen(s); if(n>26)printf("IMPOSSIBLE\n"); else { int a[26],flag[26]; memset(a,0,sizeof(a)); memset(flag,0,sizeof(flag)); for(int i=0;i<n;i++) { int t=s[i]-'a'; if(!a[t])a[t]=1,flag[i]=1; } for(int i=0;i<n;i++) { int t=s[i]-'a'; if(a[t]&&!flag[i]) { for(int j=0;j<26;j++) if(!a[j]) { s[i]=j+'a'; a[j]=1; break; } } } printf("%s\n",s); } } return 0;}
0 0
- GYM 100090 G.The Last Wish(水~)
- 4.6组队赛G题The Last Wish 字符串处理
- GYM 101147 G.The Galactic Olympics(dp)
- GYM 100694 G.The Lost Graph(栈)
- GYM 100247 G. City Square(水~)
- GYM 100247 G. City Square(水~)
- GYM 100971 G.Repair(水~)
- GYM 101086 G.Paradise City(水~)
- Gym 101028G-The Tower of Evil
- CodeForces Gym 100646G The Worm Turns
- Gym 100507G The Debut Album
- Gym 101147G - The Galactic Olympics
- GYM 100285 B. The battle near the swamp(水~)
- Gym - 100203G Good elements 水+模拟
- wish sister get the best!
- Gym 100685G Gadget Hackwrench (LCA)
- Gym 100197G Robbers (卡精度)
- Gym 100685G Gadget Hackwrench(LCA)
- 可变参数的函数
- 什么是Mixin模式:带实现的协议
- 3 伪分布式-----Nutch环境搭建和配置
- 将uid 换算为playerid
- Linux内核中断模块之中断处理函数描述
- GYM 100090 G.The Last Wish(水~)
- deviceconsole
- 利用spring session解决共享Session问题
- iOS如何在容器类(如NSMutableSet)中使用弱引用(weak reference)
- 算法提高 8皇后·改
- PHP:使用范围解析操作符
- 前端工程化学习(react+webpack+redux-form+支持ie8)
- 博为峰JavaEE技术文章 ——MyBatis Spring 整合-MapperScannerConfigurer
- HDU 4521 小明系列问题——小明序列 (DP)