【UKIEPC2015 I】【模拟】Nimionese 特殊语言转化 逻辑清晰暴力扫描
2015-11-03 19:31
537 查看
#include<stdio.h> #include<string.h> #include<ctype.h> #include<math.h> #include<iostream> #include<string> #include<set> #include<map> #include<vector> #include<queue> #include<bitset> #include<algorithm> #include<time.h> using namespace std; void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);} #define MS(x,y) memset(x,y,sizeof(x)) #define MC(x,y) memcpy(x,y,sizeof(x)) #define MP(x,y) make_pair(x,y) #define ls o<<1 #define rs o<<1|1 typedef long long LL; typedef unsigned long long UL; typedef unsigned int UI; template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;} template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;} const int N=1e4+10,M=5e4+10,Z=1e9+7,ms63=1061109567; int casenum,casei; char e[128],v[128]; char s ,w[M]; void init() { e['b']=v['b']='b'; e['c']=v['c']='c'; e['d']=v['d']='d'; e['g']=v['g']='g'; e['k']=v['k']='k'; e['n']=v['n']='n'; e['p']=v['p']='p'; e['t']=v['t']='t'; for(char ch='a';ch<='z';ch++)if(v[ch]==0) { char h=ch-1; char t=ch+1; while(1) { if(isalpha(h)) { if(e[h]) { v[ch]=h; break; } else --h; } if(isalpha(t)) { if(e[t]) { v[ch]=t; break; } else ++t; } } } } int main() { init(); while(~scanf("%s",s)) { bool ST=s[0]<='Z'; if(ST)s[0]+=32; s[0]=v[s[0]]; int m=0; bool flag=0; for(int i=0;s[i];i++) { if(flag&&e[s[i]])s[i]=s[0]; if(s[i]=='-')flag=1; else w[m++]=s[i]; } char ch=w[m-1]; if(e[ch]) { int d1=abs(ch-'a'); int d2=abs(ch-'o'); int d3=abs(ch-'u'); int d=min(d1,min(d2,d3)); if(d1==d) { w[m++]='a'; w[m++]='h'; } else if(d2==d) { w[m++]='o'; w[m++]='h'; } else { w[m++]='u'; w[m++]='h'; } }w[m]=0; if(ST){w[0]-=32;ST=0;} printf("%s",w); putchar(getchar()); } return 0; } /* 【trick&&吐槽】 1,模拟题一定要完全读懂题意,想好简化策略再做,不可操之过急。 2,这道题的样例给得十分的良心。交题之前一定要严格确保样例不出错。 3,and only the first letters of words can be upper-case 这里说的是first letters of words,都是复数,代码还是稳健的好 【题意】 我们想对一行话做加工,规则如下: 1,所有单词都必须以"硬辅音"[b,c,d,g,k,n,p,t]中的一个开头。 如果不是,替换到最接近的那个字符;如果多个选择,替换到字典序较小的。 2,我们以'-'划分音节,在第一个音节之后,所有的"硬辅音"都必须与开头字符保持一致。 3,所有以"硬辅音"为结尾的单词,都必须以同样的就近原则添加"ah","oh","uh"中的一个为结尾 4,我们应当保持原有的大小写特点,同时去除所有的'-'并输出 【类型】 模拟 【分析】 我们直接预处理出,距离每个字符最近的硬辅音是什么。 然后—— 1,要判大小写字符 2,每个单词的首字母先转化 3,如果一个位置是'-',则进入了硬辅音完全转化为开头字符的阶段。 4,如果一个位置不是'-',这个位置入串 5,如果一个位置是硬辅音,且出现过'-',则完全转化为开头字符。 6,要把大小写字符转回来。 【时间复杂度&&优化】 O(n) 【数据】 input I love ba-na-na output Gah kove bababa input Cat-a-pil-lar output Catacillar input Co-ding is the best output Cociccah gs the bestuh input I rock at co-lour-ing output Gah pockoh btuh colouriccah */
相关文章推荐
- 动易2006序列号破解算法公布
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- Transformation 能将 Windows XP/Server 2003 操作系统,完美地模拟成 Windows Vista 的软件
- 超大数据量存储常用数据库分表分库算法总结
- C#数据结构与算法揭秘二
- C#冒泡法排序算法实例分析
- 算法练习之从String.indexOf的模拟实现开始
- C#算法之关于大牛生小牛的问题
- C#实现的算24点游戏算法实例分析
- 用javascript和css模拟select的脚本
- c语言实现的带通配符匹配算法
- 浅析STL中的常用算法
- 算法之排列算法与组合算法详解
- C++实现一维向量旋转算法
- Ruby实现的合并排序算法
- C#折半插入排序算法实现方法
- 基于C++实现的各种内部排序算法汇总
- C++线性时间的排序算法分析
- C++实现汉诺塔算法经典实例