让你把所有的“连续的仅有首字母大写的”词组用缩写表示,并且在后面用括号注明原词组。

  1. #include<cstdio>
  2. #include<cstring>
  3. using namespace std;
  4. char s[130];
  5. bool iszimu(char c){
  6. return ((c>='A' && c<='Z') || (c>='a' && c<='z'));
  7. }
  8. bool isbig(char c){
  9. return (c>='A' && c<='Z');
  10. }
  11. bool issmall(char c){
  12. return (c>='a' && c<='z');
  13. }
  14. bool check(int l,int r){
  15. if(r-l+1==1){
  16. return 0;
  17. }
  18. if(!isbig(s[l])){
  19. return 0;
  20. }
  21. for(int i=l+1;i<=r;++i){
  22. if(!issmall(s[i])){
  23. return 0;
  24. }
  25. }
  26. return 1;
  27. }
  28. void print(int l,int r){
  29. for(int i=l;i<=r;++i){
  30. putchar(s[i]);
  31. }
  32. }
  33. void prin2(int l,int r){
  34. for(int i=l;i<=r;++i){
  35. if(isbig(s[i])){
  36. putchar(s[i]);
  37. }
  38. }
  39. printf(" (");
  40. for(int i=l;i<=r;++i){
  41. putchar(s[i]);
  42. }
  43. putchar(')');
  44. }
  45. int main(){
  46. freopen("abbreviation.in","r",stdin);
  47. freopen("abbreviation.out","w",stdout);
  48. while(gets(s)){
  49. int n=strlen(s),sta,cnt=0,end=-1,Sta,End=-1;
  50. for(int i=0;i<n;++i){
  51. if((i==0 || !iszimu(s[i-1])) && iszimu(s[i])){
  52. sta=i;
  53. }
  54. if((i==n-1 || !iszimu(s[i+1])) && iszimu(s[i])){
  55. if(check(sta,i) && (cnt==0 || (end==sta-2 && s[end+1]==' '))){
  56. ++cnt;
  57. if(cnt==1){
  58. Sta=sta;
  59. End=end;
  60. }
  61. }
  62. else if(check(sta,i)){
  63. if(cnt>=2){
  64. print(End+1,Sta-1);
  65. prin2(Sta,end);
  66. }
  67. else if(cnt==1){
  68. print(End+1,Sta-1);
  69. print(Sta,end);
  70. }
  71. cnt=1;
  72. Sta=sta;
  73. End=end;
  74. }
  75. else{
  76. if(cnt>=2){
  77. print(End+1,Sta-1);
  78. prin2(Sta,end);
  79. }
  80. else if(cnt==1){
  81. print(End+1,Sta-1);
  82. print(Sta,end);
  83. }
  84. print(end+1,i);
  85. cnt=0;
  86. }
  87. end=i;
  88. }
  89. }
  90. if(cnt>=2){
  91. print(End+1,Sta-1);
  92. prin2(Sta,end);
  93. }
  94. else if(cnt==1){
  95. print(End+1,Sta-1);
  96. print(Sta,end);
  97. }
  98. print(end+1,n-1);
  99. puts("");
  100. }
  101. return 0;
  102. }

【模拟】Gym - 101190A - Abbreviation的更多相关文章

  1. 【模拟】ECNA 2015 I What's on the Grille? (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 栅栏密码.给定N(N<=10),密钥为一个N*N的矩阵,'.'代表空格可以看到,'X'代表被遮挡,还有密 ...

  2. 【模拟】NEERC15 G Generators(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: n个序列.每个序列有4个值x,a,b,c,之后按照x=(a*x+b)%c扩展无穷项. 求每个序列各取一个数之后 ...

  3. 【模拟】NEERC15 J Jump(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 系统里生成一个字符串C,一开始告诉你字符串的长度N(偶数).接着你需要在n+500次内猜出这个字符串是什么. ...

  4. 【模拟】NEERC15 E Easy Problemset (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: N个人,每个人有pi个物品,每个物品价值为0~49.每次从1~n顺序选当前这个人的物品,如果这个物品的价值&g ...

  5. 【模拟】NEERC15 A Adjustment Office (2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一个N*N的矩阵A,Ai,j=i+j,Q次操作,每次分两种,R r取出第r行还未被取的所有数,并输出和.C c ...

  6. 【模拟】BAPC2014 G Growling Gears (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  7. Gym 100952C&&2015 HIAST Collegiate Programming Contest C. Palindrome Again !!【字符串,模拟】

    C. Palindrome Again !! time limit per test:1 second memory limit per test:64 megabytes input:standar ...

  8. Gym 100952B&&2015 HIAST Collegiate Programming Contest B. New Job【模拟】

    B. New Job time limit per test:1 second memory limit per test:64 megabytes input:standard input outp ...

  9. Gym 100646 Problem C: LCR 模拟题

    Problem C: LCR 题目连接: http://codeforces.com/gym/100646/attachments Description LCR is a simple game f ...

随机推荐

  1. 制作Solaris系统的USB启动盘

    制作方法: 1. wget http://192.168.2.5/surefiler-installer/2011-12-09/devel-2011.12.9.tgz 2. cd /root tar  ...

  2. hdu 1281 棋盘游戏(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1281 棋盘游戏 Time Limit: 2000/1000 MS (Java/Others)    M ...

  3. hdu 1599 find the mincost route (最小环与floyd算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1599 find the mincost route Time Limit: 1000/2000 MS ...

  4. JSOI2018简要题解

    来自FallDream的博客,未经允许,请勿转载,谢谢. 有幸拜读到贵省的题目,题的质量还不错,而且相比zjoi可做多了,简单发一下题解吧. 还有就是,怎么markdown在博客园上的代码这么丑啊 「 ...

  5. [CTF技巧]批量连接SSH批量执行命令

    https://files.cnblogs.com/files/nul1/autossh1.3.jar.zip 下载下来以后直接将后缀去除就好了. 比赛的时候可以批量写一个不死马然后你懂的. Linu ...

  6. Linux进程调度与源码分析(二)——进程生命周期与task_struct进程结构体

    1.进程生命周期 Linux操作系统属于多任务操作系统,系统中的每个进程能够分时复用CPU时间片,通过有效的进程调度策略实现多任务并行执行.而进程在被CPU调度运行,等待CPU资源分配以及等待外部事件 ...

  7. Tabular DataStream protocol 协议

    Tabular DataStream protocol 协议 Freetds 创建过程 https://wenku.baidu.com/view/2076cbfaaef8941ea76e0576.ht ...

  8. BZOJ 3656: 异或 (组合数取模 CRT)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3656 大意:经过一通推导,问题变成求\[\binom N M \mod P\],其中N,M<= ...

  9. java数组面试题

    一维数组可以写成:int[ ]x 或者int x[ ]: 二维数组可以写成:int[ ] y [ ] 或者int y[ ][ ] 或者int [ ][ ]y 面试题如下:       声明数组int[ ...

  10. js中常用的数组方法

    在数组的尾部增加或删除某个元素:push() 和 pop() push() : 在数组的尾部追加一个或多个元素,并返回数组的长度 pop():在数组的尾部删除一个元素,并返回被删除项 var arr ...