zoukankan      html  css  js  c++  java
  • 1916=字符串扩展(JAVA)

     1 import java.util.Scanner;
     2 
     3 public class Main {
     4     public static void main(String[] args) {
     5         // TODO Auto-generated method stub
     6         Scanner input = new Scanner(System.in);
     7         int T = input.nextInt();
     8         while (T-- > 0) {
     9             String str = input.next();
    10             deal(str);
    11             System.out.println();
    12         }
    13     }
    14 
    15     public static void deal(String str) {
    16         for (int i = 0; i < str.length(); i++) {
    17             if (str.charAt(i) == '-') {
    18                 if (i == 0 || i == str.length() - 1) {
    19                     System.out.print('-');
    20                 } else {
    21                     if (str.charAt(i - 1) >= 'a' && str.charAt(i - 1) <= 'z' && str.charAt(i + 1) >= 'a'
    22                             && str.charAt(i + 1) <= 'z' && str.charAt(i - 1) <= str.charAt(i + 1)) {
    23                         for (int j = (int) (str.charAt(i - 1) + 1); j < (int) (str.charAt(i + 1)); j++) {
    24                             System.out.print((char) (j));
    25                         }
    26                     } else if (str.charAt(i - 1) >= '0' && str.charAt(i - 1) <= '9' && str.charAt(i + 1) >= '0'
    27                             && str.charAt(i + 1) <= '9' && str.charAt(i - 1) <= str.charAt(i + 1)) {
    28                         for (int j = (int) (str.charAt(i - 1) + 1); j < (int) (str.charAt(i + 1)); j++) {
    29                             System.out.print((char) (j));
    30                         }
    31                     } else if (str.charAt(i - 1) >= 'A' && str.charAt(i - 1) <= 'Z' && str.charAt(i + 1) >= 'A'
    32                             && str.charAt(i + 1) <= 'Z' && str.charAt(i - 1) <= str.charAt(i + 1)) {
    33                         for (int j = (int) (str.charAt(i - 1) + 1); j < (int) (str.charAt(i + 1)); j++) {
    34                             System.out.print((char) (j));
    35                         }
    36                     } else
    37                         System.out.print('-');
    38 
    39                 }
    40             } else
    41                 System.out.print(str.charAt(i));
    42         }
    43     }
    44 }
  • 相关阅读:
    Programming Collecive Intelligence 笔记 Making Recommendations
    Managing Gigabytes文本压缩
    Hadoop The Definitive Guide 笔记二
    POS Tagging with NLTK
    MG查询
    MG索引构造
    对SharePoint 2010的job failover的一些比较深入的说明
    SharePoint 2010中Search功能的数据库连接字符串在哪里?
    记解决一个数据库删不掉的问题
    SharePoint升级失败?
  • 原文地址:https://www.cnblogs.com/Angfe/p/11821221.html
Copyright © 2011-2022 走看看