01-08 08:57
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_3 ๋ฌธ์žฅ ์† ๋‹จ์–ด ๋ณธ๋ฌธ

Algorithm/Java

[Algorithm]์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ž๋ฐ”_3 ๋ฌธ์žฅ ์† ๋‹จ์–ด

miinsun 2022. 1. 2. 23:01

 

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช…

ํ•œ ๊ฐœ์˜ ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง€๋ฉด ๊ทธ ๋ฌธ์žฅ ์†์—์„œ ๊ฐ€์žฅ ๊ธด ๋‹จ์–ด๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์„ธ์š”.
๋ฌธ์žฅ์†์˜ ๊ฐ ๋‹จ์–ด๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋ฉ๋‹ˆ๋‹ค.

 

 

๐Ÿ”จ ์ž…์ถœ๋ ฅ ์˜ˆ

์ž…๋ ฅ - ์ฒซ ์ค„์— ๊ธธ์ด๊ฐ€ 100์„ ๋„˜์ง€ ์•Š๋Š” ํ•œ ๊ฐœ์˜ ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ๋ฌธ์žฅ์€ ์˜์–ด ์•ŒํŒŒ๋ฒณ์œผ๋กœ๋งŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

it is time to study

์ถœ๋ ฅ - ์ฒซ ์ค„์— ๊ฐ€์žฅ ๊ธด ๋‹จ์–ด๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๊ฐ€์žฅ ๊ธธ์ด๊ฐ€ ๊ธด ๋‹จ์–ด๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ์ผ ๊ฒฝ์šฐ ๋ฌธ์žฅ์†์—์„œ ๊ฐ€์žฅ ์•ž์ชฝ์— ์œ„์น˜ํ•œ ๋‹จ์–ด๋ฅผ ๋‹ต์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

study

โ€‹

๐Ÿ’ป Solution.java

import java.util.Scanner;
  
public class Main {
	public String solution(String str) {
		String answer = "";
		String[] strArr = str.split(" ");
		
		int maxLen = Integer.MIN_VALUE;
		for(String s : strArr) {
			if(s.length() > maxLen) {
				maxLen = s.length();
				answer = s;
			}
		}
		return answer;
	}
	
	public static void main(String[] args){
		Main main  = new Main();
		Scanner sc =new Scanner(System.in);
		String str = sc.nextLine();
		
		System.out.println(main.solution(str));
		sc.close();
		return ;
	}
}

 

Comments