码迷,mamicode.com
首页 > 其他好文 > 详细

hihocoder 1197 Give My Text Back

时间:2017-03-30 19:43:31      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:amp   limits   ack   ios   code   coder   bsp   char   stream   

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <iostream>
 4 #include <string.h>
 5 #include <limits.h>
 6 #include <queue>
 7 #include <vector>
 8 #include <set>
 9 #include <map>
10 #include <algorithm>
11 
12 using namespace std;
13 
14 
15 char buf[10000];
16 
17 bool iszimu(char c) {
18     return ((c>=a && c<=z) || (c>=A && c<=Z));
19 }
20 char turn_capital(char c) {
21     if (c>=a && c<=z) {
22         c = c + A - a;
23     }
24     return c;
25 }
26 char turn_small(char c) {
27     if (c>=A && c<=Z) c = c+a-A;
28     return c;
29 }
30 int main()
31 {
32     while(scanf("%[^\n]", buf)>0){
33         //printf("%s\n", buf);
34         char str[10000] = {0};
35         int j = 0;
36         for (int i=0;buf[i]!=0;++i) {
37             if (iszimu(buf[i])) {
38                 if (j==0 || str[j-2] == .) {
39                     str[j] = turn_capital(buf[i]);
40                 } else {
41                     str[j] = turn_small(buf[i]);
42                 }
43             } else if (buf[i] ==  ) {
44                 if (j==0) continue;
45                 if (str[j-1] !=  ) str[j] = buf[i];
46                 else j--;
47             } else if (buf[i] == , || buf[i] == .) {
48                 if (str[j-1] ==  ) {
49                     str[j-1] = buf[i];
50                     str[j] =  ;
51                 } else {
52                     str[j] = buf[i];
53                     str[j+1] =  ;
54                     j++;
55                 }
56             }
57             j++;
58         }
59         printf("%s\n", str);
60         getchar();
61     }
62 }

 

hihocoder 1197 Give My Text Back

标签:amp   limits   ack   ios   code   coder   bsp   char   stream   

原文地址:http://www.cnblogs.com/suwish/p/6647209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!