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

백준 C#11718 2023-07-21

by 하타라시 2023. 7. 21.
using System.Text; //스트링빌더때 필요함
 
StringBuilder stringBuilder = new StringBuilder(); //스트링 빌더
    string put = string.Empty; //초기화
    while(true){
        put = Console.ReadLine();
        if(string.IsNullOrEmpty(put)) break; //vscode에서는 아무리봐도 이상한 결과인데 백준에선 정답이여서 그냥 때려쳤음..
        stringBuilder.AppendLine(put); //list에서 Add 역할
    }
    Console.WriteLine(stringBuilder); 

첫 번째 트라이때 했던 것

string? put = string.Empty; //입력 받을 곳
    StringBuilder stringBuilder = new StringBuilder();
    Regex regex = new Regex(@"([0-9a-zA-Z])+$"); //숫자 소문자 대문자 이고 이전 패턴이 하나 이상은 포함되야함.
    bool result = false;
    do{
        put = Console.ReadLine();
        result = regex.IsMatch(put);
        stringBuilder.Append(put + "\n");
    } while(result); //true면 탈출
    Console.WriteLine(stringBuilder);

메모리랑 소요시간 차이가 확실히 있구나를 느꼈던 문제.