zoukankan      html  css  js  c++  java
  • Java实现 蓝桥杯VIP 算法训练 最长字符串

    题目描述
    字符串可是比赛经常出的问题,那么给大家出一个题,

    输入五个字符串,输出5个字符串当中最长的字符串。每个字符串长度在100以内,且全为小写字母。

    输入

    输出

    样例输入
    one two three four five
    样例输出
    three

    import java.util.Scanner;
    
    
    public class 最长字符串 {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		String a[] = new String[5];
    		int max = 0;// 最长字符串的位数
    		int t = 0;// 记录第几个字符串位数最大
    		for (int i = 0; i < 5; i++) {
    			a[i] = sc.next();
    			if (max < a[i].length()) {
    				max = a[i].length();
    				t = i;
    			}
    		}
    		System.out.println(a[t]);
    	}
    
    
    }
    
    
  • 相关阅读:
    HDU 3709 Balanced Number
    HDU 3652 B-number
    HDU 3555 Bomb
    全局和局部内存管理
    [转]
    [转]
    [转]
    The Stable Marriage Problem
    STL各种容器的使用时机详解
    Qt中图像的显示与基本操作
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13078648.html
Copyright © 2011-2022 走看看