zoukankan      html  css  js  c++  java
  • codeforces A. Punctuation 解题报告

    题目链接:http://codeforces.com/problemset/problem/147/A

    题目意思:给定一篇文章,需要对这篇文章进行编辑,使得:(1)两个单词之间有一个空格分开  (2)标点符号前面(, . ! ?)没有空格,即单词后面直接紧跟着这个标点  (3)标点符号后面只有一个空格。

          恶心的字符串处理。特别要注意,当出现类似   wery   ,   weyriu    的形式时的处理方法。由于对于标点符号的处理,我是把该符号+空格输出,所以对于这种情况,再把空格都过滤了的情况下,仅当紧跟着空格后面的那个字符不能为标点符号而是小写字母并且该空格前面有一个空格的时候,才输出空白符。

        

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 const int maxn = 1e4 + 5;
     8 char s[maxn];
     9 
    10 int main()
    11 {
    12     int i, j, len;
    13     while (gets(s))
    14     {
    15         len = strlen(s);
    16         for (i = 0; i < len; i++)
    17         {
    18             if (s[i] == '
    ')
    19                 break;
    20             if (s[i] >= 'a' && s[i] <= 'z')
    21                 printf("%c", s[i]);
    22             else if (s[i] == '.' || s[i] == ',' || s[i] == '!' || s[i] == '?')
    23                 printf("%c ", s[i]);
    24             else 
    25             {
    26                 j = i;
    27                 while (s[i] == ' ' && i < len)
    28                     i++;
    29                 if (i < len)
    30                 {
    31                     if (s[j] == ' ' && (s[j-1] >= 'a' && s[j-1] <= 'z') && (s[i] != '.' && s[i] != ',' && s[i] != '!' && s[i] != '?'))    // 特别要注意的情况!!
    32                         printf(" ");
    33                     i--;
    34                 }
    35             }
    36         }
    37         printf("
    ");
    38     }
    39     return 0;
    40 }
    41     
  • 相关阅读:
    LR遇到的问题
    常用的mysql操作
    mysql操作
    土地档案管理系统架构图,ER图,用例图
    土地档案管理系统需求分析
    Load data local infile
    Lamda Expression
    Domain Logic approaches
    Spring AOP Capabilities and Goals
    python
  • 原文地址:https://www.cnblogs.com/windysai/p/3533214.html
Copyright © 2011-2022 走看看