사용언어 : Java
문제

풀이
/*
chicken = 1081
coupon = 1081
total = 0
bonus : coupon / 10 = 108 ... 1
coupon = 109
total = 108
bonus : coupon / 10 = 10 ... 9
coupon = 19
total = 118
bonus : coupon / 10 = 1 ... 9
coupon = 10
total = 119
bonus : coupon / 10 = 1
coupon = 1
total = 120
return total = 120
*/
class Solution {
public int solution(int chicken) {
int answer = 0;
while(true)
{
answer += chicken / 10;
chicken = (chicken / 10) + (chicken % 10);
if(chicken < 10) break;
}
return answer;
}
}
Share article