SRM 149 DIV 2 (250)
Programming/SRM Practice 2009. 9. 15. 23:04문제 요약 : dollars, cents 표기법에 맞게 출력하기
using System;
public class FormatAmt
{
public string amount(int dollars, int cents)
{
string res = "", temp = dollars.ToString();
for (int i = temp.Length - 1; i >= 0; i--)
{
res = temp[i] + res;
if ((temp.Length - i) % 3 == 0 && i != 0) res = "," + res;
}
if (cents.ToString().Length > 1) res += "." + cents.ToString();
else res += ".0" + cents.ToString();
return "$" + res;
}
}
'Programming > SRM Practice' 카테고리의 다른 글
SRM 150 DIV 2 (250) (0) | 2009.09.15 |
---|---|
SRM 307 DIV 2 (250) (0) | 2009.07.04 |
SRM 191 DIV 2 (250) (0) | 2009.05.30 |
SRM 148 DIV 2 (250) (0) | 2009.05.27 |
SRM 146 DIV 2 (250) (0) | 2009.05.27 |