Skip to content

Instantly share code, notes, and snippets.

@DongguemYoo
Created May 1, 2020 07:00
Show Gist options
  • Save DongguemYoo/ffbc74cb917c51b060a79a4e1cce1eac to your computer and use it in GitHub Desktop.
Save DongguemYoo/ffbc74cb917c51b060a79a4e1cce1eac to your computer and use it in GitHub Desktop.
코딩테스트 연습 문자열 다루기 기본
///내가 푼 방식 개 무식 하게 풀엇음 ㅎㅅㅎ;
public bool solution(string s)
{
char[] a = s.ToCharArray();
if (!(4 == a.Length || a.Length == 6))
return false;
for (int i = 0; i < a.Length; i++)
{
if (Convert.ToInt32(a[i]) >= 65 && 90 >= Convert.ToInt32(a[i])
|| Convert.ToInt32(a[i]) >= 97 && 122 >= Convert.ToInt32(a[i]))
return false;
}
return true;
}
//다른사람이 푼 방식중 가장 마음에 드는것
####int.TryParse 는 숫자가 아닌 문자가 끼어있으면 false를 리턴하고 out 매개변수에 0을 넣는다####
####전부다 숫자라면 TRUE를 return 하고 out매개변수에 해당하는 숫자를 넣는다!!####
public class Solution {
public bool solution(string s) {
bool answer = false;
if (s.Length == 4 || s.Length == 6)
answer = int.TryParse(s, out int i);
return answer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment