首页 > 编程语言 > 详细

算法训练 最长字符串

时间:2016-04-03 22:05:52      阅读:292      评论:0      收藏:0      [点我收藏+]
算法训练 最长字符串  
时间限制:1.0s   内存限制:512.0MB
    
  求出5个字符串中最长的字符串。每个字符串长度在100以内,且全为小写字母。
样例输入
one two three four five
样例输出
three
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        String s[]=str.split(" ");
        int len=s[0].length(); 
        int p=0;
        for(int i=1;i<s.length;i++){
            if(len<s[i].length()){ 
                len=s[i].length();
                p=i;
            }
        }
        System.out.println(s[p]);

    }

}

 

算法训练 最长字符串

原文:http://www.cnblogs.com/watchfree/p/5350662.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!