hihocoder 1197 Give My Text Back

 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 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值