【UKIEPC2015 I】【模拟】Nimionese 特殊语言转化 逻辑清晰暴力扫描

来源:互联网 发布:聊天软件排名 编辑:程序博客网 时间:2024/06/08 19:52
#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|1typedef 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[N],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)【数据】inputI love ba-na-naoutputGah kove bababainputCat-a-pil-laroutputCatacillarinputCo-ding is the bestoutputCociccah gs the bestuhinputI rock at co-lour-ingoutputGah pockoh btuh colouriccah*/


1 0
原创粉丝点击