zoukankan      html  css  js  c++  java
  • hihocoder 1197

    http://hihocoder.com/problemset/problem/1197

    这个题目做了还是很久。因为很多地方没看明白

    1.每个语句是说以.结尾,那么.后面的语句应该就是新的一个语句了(首字母得大写)

    2.每个语句,后面可能会少一个空格,你应该加上去(指逗号后面紧跟着字符的)

    然后代码参考了一下别人的。。。

     1 import java.util.Scanner;
     2 
     3 public class Main {
     4 
     5     public static void main(String[] args) {
     6 
     7         Scanner cin = new Scanner(System.in);
     8         while (cin.hasNext()) {
     9             String str = cin.nextLine();
    10             for (int i = 0; i < str.length(); i++)
    11                 if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')
    12                     str = str.replace(str.charAt(i), (char) (str.charAt(i) - 'A' + 'a'));
    13             String ans = "";
    14             boolean flag = false;
    15             boolean first = false;
    16             for (int i = 0; i < str.length(); i++) {
    17                 if(str.charAt(i)!=' '){
    18                     if(str.charAt(i)==','){
    19                         ans+=", ";
    20                     }else if(str.charAt(i)=='.'){
    21                         ans+=". ";
    22                         first = false;
    23                     }else {
    24                         if(!flag&&first&&!ans.endsWith(" "))
    25                             ans+=" ";
    26                         if(!first){
    27                             ans+=(char)(str.charAt(i)-'a'+'A');
    28                             first = true;
    29                         }else 
    30                             ans+=str.charAt(i);
    31                         flag = true;
    32                     }
    33                 }else 
    34                     flag = false;
    35             }
    36             System.out.println(ans);
    37         }
    38     }
    39 }
  • 相关阅读:
    HTML5 模板推荐
    OpenCV初探
    微信开放框架-UCToo
    ProFTPD 初探
    移动开发者服务平台-友盟
    线程原理理解
    JVM参数及性能调优
    GC——垃圾回收
    JVM内存模型
    php常用 随机数
  • 原文地址:https://www.cnblogs.com/Tree-dream/p/7091160.html
Copyright © 2011-2022 走看看