๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
SWEA

[SWEA] 2050. ์•ŒํŒŒ๋ฒณ์„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜

by JulesJ 2022. 5. 17.
728x90

 

[SWEA] 2050. ์•ŒํŒŒ๋ฒณ์„ ์ˆซ์ž๋กœ ๋ณ€ํ™˜ - D1

 

1. String์œผ๋กœ ๋ฌธ์ž์—ด์„ ๋ฐ›๋Š”๋‹ค.

2. CharAt๋ฅผ ์ด์šฉํ•ด ๋ถ„๋ฆฌํ•œ๋‹ค

3. ์•„์Šคํ‚ค ์ฝ”๋“œ์—์„œ ๋ฌธ์ž 'A' ๊ฐ€ ์ˆซ์ž 65์ด๋ฏ€๋กœ, ๊ฐ’์—๋‹ค 'A'+1์„ ํ•ด์ค€๋‹ค.

(CharAt() : String์œผ๋กœ ์ €์žฅ๋œ ๋ฌธ์ž์—ด ์ค‘์—์„œ ํ•œ ๊ธ€์ž๋งŒ ์„ ํƒํ•ด์„œ charํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜)

 

- toCharArray๋ฅผ ์ด์šฉํ•ด์„œ ๋ถ„๋ฆฌํ•ด๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

import java.util.Scanner;
import java.io.FileInputStream;

class Solution
{
	public static void main(String args[]) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        
		for(int i = 0; i < s.length(); i++){
			int num = (int)s.charAt(i);
			System.out.print(num-'A'+1+" ");
		}

	}
}

 

 

๋ ๐Ÿง

๋Œ“๊ธ€