프로그래밍
[HackerRank] Number of ID
tedhong
2023. 2. 20. 12:55
2019-07-16 글쓴이 TED HONG
[HackerRank] Number of ID
Input값은 숫자로 된 문자열.
이를 재조합 하여 사원 번호를 만든다고 가정할 때 몇개를 만들 수 있는지 찾는 문제.
조건 1 : 사원번호는 8로 시작함
조건 2 : 사원번호는 11자리 숫자로 구성됨
public static int numOfIds(string pool)
{
List list = new List(pool.ToCharArray());
//int firstIdx = list.IndexOf('8')+ 1;
int cnt = list.Count;// - firstIdx;
int d = cnt / 11;
int r = cnt % 11;
Console.WriteLine(string.Format("firstIdx = {0} / cnt ={1} / d = {2} / r = {3}", 0, cnt, d, r));
string str = "8";
int tCnt = list.Count(s => str.Contains(s));
Console.WriteLine("tCnt = "+ tCnt);
return Math.Min(d, tCnt);
}