题解 | #单词倒排#

单词倒排

http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

    Scanner in = new Scanner(System.in);

    String inString = in.nextLine();

    //String inString = "aade *  $afaefeafeafwafaefeafawf* fafaf";

    String result = calc(inString);

    System.out.println(result);

}

public static String calc(String inString){

    StringBuffer sb = new StringBuffer(inString);
    StringBuffer temp = new StringBuffer();

    int count = 0;
    for(int i=0;i<sb.length();i++){
        if(count == 20){
            count = 0;
            temp.append(" ");
        }

        char c = sb.charAt(i);
        if( ( 'A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') ){
            temp.append(c);
            count++;
            continue;
        }

        if(temp.length() == 0){
            continue;
        }

        if(temp.charAt(temp.length()-1) == ' '){
            continue;
        }

        temp.append(" ");
        count = 0;
    }

    String[] res =  temp.toString().split(" ");

    StringBuffer result = new StringBuffer();
    for(int i= res.length-1;i > -1;i--){
        result.append(res[i]).append(" ");
    }

    return result.substring(0,result.length()-1);
}

}

全部评论

相关推荐

07-17 11:50
门头沟学院 Java
投递腾讯等公司7个岗位
点赞 评论 收藏
分享
06-12 16:00
天津大学 Java
牛客30236098...:腾讯坏事做尽,终面挂是最破防的 上次被挂了后我连简历都不刷了
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务