본문 바로가기
카테고리 없음

백준 #2941 2023-07-26

by 하타라시 2023. 7. 26.
Regex regex = new Regex(@"(c=)|(c-)|(dz=)|(d-)|(lj)|(nj)|(s=)|(z=)");  //정규식
        string input = regex.Replace(Console.ReadLine(),"1");  //1로 변환
        Console.WriteLine(input.Length);
  // -----------------------------------------------------------------------------------------------
        string put = Console.ReadLine();
        string[] crotia = new string[] { "c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z=" };  //배열에 저장

        for(int i = 0; i < crotia.Length; i++)
            put = put.Replace(crotia[i],"1");  //일일이 Replace실행
        Console.WriteLine(put.Length); //출력

순서 반대로임당

위에꺼는 104ms << 직접 짠 코드   

아래꺼는 60ms << 참고해서 돌려본 코드

 

Regex가 느리긴 하구나 느낌