์ฒด๊ฐ Level : โ
โ
โ Review: ์์คํค์ฝ๋๋ฅผ ์ด์ฉํด์ผํจ |
๐ก
๊ฐ์ ๋ฐ๋ผ์ ์ผ์์๋ฆฌ,์ญ์์๋ฆฌ,๋ฐฑ์์๋ฆฌ,์ฒ์์๋ฆฌ๋ฅผ ๊ฐ์ ธ์์
(a) 97 ์ ๋ํด์ค์ ์ํ๋ฒณ์ผ๋ก ๋ง๋ค์ด์ฃผ์๋ค.
ํ๊ธด ํ์๋๋ฐ !!!!
์ฝ๋๊ฐ ๋งค์ฐ ๋์กํ๊ณ ... ๊ธธ๊ณ ์ค๋ณต์ด ๋ง์์ ๋ณด๊ธฐ ์ข์ง์๋ค... ๐ญ ๐ญ ๐ญ
class Solution {
public String solution(int age) {
String answer = "";
// a = 0 b = 1 97 98
int num1 =0, num2 =0, num3 =0, num4 =0;
if ( age < 10){
num1 = 97 + age;
answer = String.valueOf((char)num1);
}
else if (10 <= age && age < 100) {
num1 = 97 + age / 10;
num2 = 97 + age % 10;
answer = String.valueOf((char)num1);
answer += String.valueOf((char)num2);
}
else if (100 <= age && age < 1000) {
num1 = 97 + age / 100;
num2 = 97 + age % 100 /10;
num3 = 97 + age % 10;
answer = String.valueOf((char)num1);
answer += String.valueOf((char)num2);
answer += String.valueOf((char)num3);
}else {
num1 = 97 + age / 1000;
num2 = 97 + age % 1000 /100;
num3 = 97 + age % 100 /10;
num4 = 97 + age % 10;
answer = String.valueOf((char)num1);
answer += String.valueOf((char)num2);
answer += String.valueOf((char)num3);
answer += String.valueOf((char)num4);
}
return answer;
}
}
โญ ์ข์ ์ฝ๋ ๋ฆฌ๋ทฐ !
age ๋ฅผ string ์ผ๋ก ๋ณํํด์ ์๋ฆฌ์๋ฅผ ๊ฐ์ ธ์๋ค!
๊ทธ๋ฆฌ๊ณ ๋ฌธ์์ด ์๋ฆฌ๋ง๋ค + 49 ๋ฅผ ๋ํด์ ์ํ๋ฒณ์ผ๋ก ๋ง๋ค์ด์คฌ๋ค !!
๐ฌ ์์คํค ์ฝ๋๊ฐ A 65 , a 97 , 0์ 48 ~ 1 ์ 49 ~ 9๋ 57 ์ด๋ค.
0 ์์คํค ๊ฐ 48
+ 49๋ฅผ ๋ํด์ฃผ๋ฉด
--------------------------
=> a 97 ์ด ๋๋ค
์ฆ ์ซ์์ ๋ฐ๋ผ์ a~j ๊น์ง ํํ๊ฐ๋ฅ !!!
class Solution {
public String solution(int age) {
String ageToOutsideAge = Integer.toString(age);
String result = "";
for(int i = 0; i < ageToOutsideAge.length(); i++)
{
result += (char)(ageToOutsideAge.charAt(i) + 49);
}
return result;
}
}