이 페이지는 코딩도장 데이터의 읽기 전용 정적 보관본입니다.

폰번 게시글 검사

당신은 A 인터넷 카페 운영자이다.

당신의 인터넷 카페에는 휴대폰 번호 게시가 금지되어 있다.

하지만 일부 회원들이 편법을 동원하여 휴대폰 번호를 게시 후 불법 거래를 시도한다.

이를 체크하여 자동 삭제를 할 수 있도록 휴대폰 번호 검사 알고리즘을 작성하시오.

(011~019 는 10자리여도 휴대폰 번호이다. 010은 11자리여야만 한다.)

Input

영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이

Output

01099781984 true
0107778234 false
0173758282 true
01134994592 true

2018/08/31 22:01

김지훈

33개의 풀이가 있습니다.

def checknum(string):
    result = ''
    exc = {'영':0, '일':1, '이':2, '삼':3, '사':4, '오':5, '육':6, '칠':7, '팔':8, '구':9}
    for a in string:
        if a in exc: result += str(exc[a])
        elif a in '0123456789': result += a
    if result[:3] == '010':
        if len(result) == 11: return True
        else: return False
    elif result[:3] in ['0' + str(x) for x in range(11, 20)] and len(result) <= 11 and len(result) >= 10: return True
    else: return False

2018/09/01 16:11

myyh2357

def phonenumber_validator(v):
  t = {'일':1, '이':2, '삼':3, '사':4, '오':5, '육':6, '칠':7, '팔':8, '구':9, '영':0}
  num = ''.join(i if i.isdigit() else str(t.get(i,'')) for i in v)
  return num, (num[:3] == '010' and len(num) == 11) or \
              (num[:3] != '010' and num[:2] == '01' and len(num) in [10,11])

sample = '''\
영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이'''

for i in sample.splitlines(): print(phonenumber_validator(i))

2018/09/02 02:29

Creator

input_str = '''영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이'''

dic = dict(zip('0123456789영일이삼사오육칠팔구공륙', '0123456789012345678906'))
for string in input_str.split('\n'):
    numbers = ''.join([dic[c] for c in string if c in dic])
    is_valid = len(numbers) == 11 and numbers[:3] == '010' or \
               len(numbers) >= 10 and numbers[:3] in ['01' + n for n in '123456789']

    print(numbers, is_valid)

2018/09/04 15:17

Noname

var myString = prompt('', '');

var CheckNum = '0123456789';

var myMobileNum = ''; var myResult;

for(i=0; i<myString.length;i++)

{

var myNum = myString[i];

switch(myString[i])

{

case '영':

myNum = 0;

break;

case '일':

myNum = 1;

break;

case '이':

myNum = 2;

break;

case '삼':

myNum = 3;

break;

case '사':

myNum = 4;

break;

case '오':

myNum = 5;

break;

case '육':

myNum = 6;

break;

case '칠':

myNum = 7;

break;

case '팔':

myNum = 8;

break;

case '구':

myNum = 9;

break;

}

if(CheckNum.indexOf(myNum) > -1)

{

myMobileNum += myNum.toString();

}

}

if(myMobileNum.substring (0, 3) == '010' && myMobileNum.length == 11)

{

myResult = true;

}

else if(myMobileNum.substring (0, 2) == '01' && CheckNum.indexOf(myMobileNum[2]) > 0 && myMobileNum.length == 10 || myMobileNum.length == 11)

{

myResult = true;

}

else

{

myResult = false;

}

alert(myResult);

2018/09/06 16:00

jey0109

python2.7

def phone(x):
    a = x.split("\n")
    text = ["영","일","이","삼","사","오","육","칠","팔","구"]
    number = ["0","1","2","3","4","5","6","7","8","9"]
    for i in range(len(a)-2):
        b = a[i+1]
        for y in ["-","."," "]:
            while y in b:
                b = b[:b.index(y)] + b[(b.index(y)+1):]
        for i in range(len(text)):
            while text[i] in b:
                b = b[:b.index(text[i])] + number[i] + b[(b.index(text[i])+3):]
        print(b),; print(b[:1]=="01"&((b[2]=="0"&len(b)==11)|(b[2]!="0"&len(b)in[10,11]))

2018/09/06 16:01

tarte24



def korToNum(strVal):
    if strVal == "영" or strVal == "공" or strVal == "땡" or strVal == "0":
        return "0"
    elif strVal == "일" or strVal == "1":
        return "1"
    elif strVal == "이" or strVal == "둘" or strVal == "2":
        return "2"
    elif strVal == "삼" or strVal == "셋" or strVal == "3":
        return "3"
    elif strVal == "사" or strVal == "넷" or strVal == "4":
        return "4"
    elif strVal == "오" or strVal == "5":
        return "5"
    elif strVal == "육" or strVal == "6":
        return "6"
    elif strVal == "칠" or strVal == "7":
        return "7"
    elif strVal == "팔" or strVal == "8":
        return "8"
    elif strVal == "구" or strVal == "9":
        return "9"
    else:  # 인식할 수 없는 수의 표현 또는 수가 아닌 표현
        return ""
    # else:
    #     print("잘못된 입력 : " + strVal)

def isValidPhnum(phoneNum):
    if phoneNum[:2] != "01": #01로 시작해야함
        return False
    elif phoneNum[2:3] == "0" and len(phoneNum) != 11: #010이면 11자리
        return False
    elif len(phoneNum) != 11 and len(phoneNum) != 10: #01x이면 10,11자리
        return False
    else:
        return True

getVal = input()

numVal = ""
for chr_i in getVal:
    numVal = numVal + korToNum(chr_i)

print(numVal + " " + str(isValidPhnum(numVal)))

2018/09/07 18:01

셈우

C#

using System;
using System.Text;

namespace CD195
{
    class Program
    {
        enum Digits { 영, 일, 이, 삼, 사, 오, 육, 칠, 팔, 구 }; // 영 = 0, 일 = 1, ...

        static void Main(string[] args)
        {
            bool result = Str2Num(Console.ReadLine(), out string converted);
            Console.WriteLine($"{converted} {result}");
        }

        static bool Str2Num(string aString, out string result)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var s in aString)
            {
                // 숫자:그대로, Enum에 정의된 경우: 문자=>Enum.문자값
                if (Char.IsDigit(s)) sb.Append(s);
                else if (Enum.IsDefined(typeof(Digits), s.ToString()))
                {
                    sb.Append((int)Enum.Parse(typeof(Digits), s.ToString()));
                }
            }
            result = sb.ToString();
            // 길이 유효성 체크
            if (sb[2] == '0') return sb.Length == 11;
            else return sb.Length == 10 || sb.Length == 11;
        }
    }
}

2018/09/12 11:26

mohenjo

// =============================================
    private static String phoneCheck(String phone) {
        String temp;
        temp = phone.replaceAll("[^\uAC00-\uD7A3xfe0-9a-zA-Z]", "")
                .replaceAll("영", "0").replaceAll("일", "1").replaceAll("이", "2").replaceAll("삼", "3")
                .replaceAll("사", "4").replaceAll("오", "5").replaceAll("육", "6").replaceAll("칠", "7")
                .replaceAll("팔", "8").replaceAll("구", "9");
        if (temp.matches("^010(?:\\d{4})\\d{4}$")) {
            return temp + " " + true;
        }
        if (temp.matches("^01(?:1|[6-9])(?:\\d{3}|\\d{4})\\d{4}$")) {
            return temp + " " + true;
        }
        return temp + " " + false;
    }

2018/09/17 17:09

채규빈

'''
당신은 A 인터넷 카페 운영자이다.
당신의 인터넷 카페에는 휴대폰 번호 게시가 금지되어 있다.
하지만 일부 회원들이 편법을 동원하여 휴대폰 번호를 게시 후 불법 거래를 시도한다.
이를 체크하여 자동 삭제를 할 수 있도록 휴대폰 번호 검사 알고리즘을 작성하시오.
(011~019 는 10자리여도 휴대폰 번호이다. 010은 11자리여야만 한다.)
'''

test_input = """영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이"""
test_output = """01099781984 true
0107778234 false
0173758282 true
01134994592 true"""

numbers = "0123456789영일이삼사오육칠팔구"
kor = "01234567890123456789"
kor_numbers = dict(zip(numbers, kor))
print (kor_numbers)

def FindFakePhoneNumber(input):
    #print(input)
    output_numbers = ''.join([kor_numbers[ch] for ch in input if ch in kor_numbers])
    print(output_numbers)

    local_code = output_numbers[:3]
    #print(local_code)

    if local_code == "010" and len(output_numbers)==11:        
        return output_numbers + " true"
    if 11 <= int(local_code) and int(local_code) <= 19:
        if len(output_numbers) == 10 or len(output_numbers) == 11:
            #print(output_numbers + " true")
            return output_numbers + " true"

    return output_numbers + " false"



test_input_list = test_input.split("\n")
test_output_list = test_output.split("\n")
for i in range(len(test_input_list)):
    assert FindFakePhoneNumber(test_input_list[i]) == test_output_list[i]

2018/09/17 22:25

phg98

def cp(sen):
    l = []
    for x in list(sen):
        if x in '영일이삼사오육칠팔구' or x.isdigit():
            l.append(x if x.isdigit() else str('영일이삼사오육칠팔구'.index(x)))
    print(''.join(l),'true' if l[0] == '0' and len(l) == (11 if l[2] == '0' else 10) else 'false')

2018/10/01 20:10

김영성

def Chk_PhoneNumber(a) :
    #dictionary 생성
    num="영일이삼사오육칠팔구"
    dic_num={'공': '0' }
    for n in range(0, 10) :
        dic_num[num[n]]= str(n)
    #불필요한 문자 제거, 문자를 숫자로 치환
    phone_num =""
    for n in a :
        for k, v in dic_num.items() :
            if str(n) in (k, v) :
                if str(n) in (k) :
                    phone_num+=dic_num[n]
                else :
                    phone_num+=n
                break
    #휴대폰 번호 점검  
    if phone_num[0:2]=='01' :
        if phone_num[2]=='0' and len(phone_num)!=11 :
            return print(phone_num + ": false")
        else :
            if len(phone_num)==10 or len(phone_num)==11 :
                return print(phone_num + ": true")
    else : 
        return print(phone_num+ ": false")

2018/11/05 22:48

쨔이

raw = str()
for i in input():
    if i in "0123456789영일이삼사오육칠팔구":
        raw += i

produce = (raw.replace("영","0").replace("일","1").replace("이","2").replace("삼","3")
           .replace("사","4").replace("오","5").replace("육","6").replace("칠","7")
           .replace("팔","8").replace("구","9"))

if produce[0] == "0" and produce[1] == "1":
    if produce[2] == "0":
        if len(produce) == 11:
            print("True")
        else:
            print("False")
    else:
        if len(produce) == 10 or len(produce) == 11:
            print("True")
        else:
            print("False")
else:
    print("False")

2018/11/13 22:35

그사람 남한 볼 수 있어요

public class Solution {

    public static void main(String[] args) {
//      System.out.println("9".charAt(0) + 0);
        String[] arr = {"영일영-구구칠8-일구팔사", "0일영.칠칠칠팔.이삼사", "영 일 칠 삼 칠 오 팔 이 팔 이", "영일일 34구구 4 오 9 이"};
        boolean[] arr_bol = new boolean[4];
        for(int i = 0; i < arr.length; i++) {
            arr[i] = arr[i].replaceAll("[^\uAC00-\uD7A3xfe0-9a-zA-Z\\s]| ", "")
                    .replaceAll("영", "0").replaceAll("일", "1").replaceAll("이", "2").replaceAll("삼", "3")
                    .replaceAll("사", "4").replaceAll("오", "5").replaceAll("육", "6").replaceAll("칠", "7")
                    .replaceAll("팔", "8").replaceAll("구", "9");
            if(arr[i].substring(0, 2).equals("01")) {
                if(arr[i].substring(2, 3).equals("0") && arr[i].length() == 11) {
                    arr_bol[i] = true;
                }else if(arr[i].substring(2, 3).charAt(0) >= 49 && arr[i].substring(2, 3).charAt(0) <= 57 
                        && (arr[i].length() == 10 || arr[i].length() == 11)) {
                    arr_bol[i] = true;
                }
            }
            System.out.println(arr[i] + " " + arr_bol[i]);
        }
    }

}

2018/11/26 14:06

윤태준

#폰번 게시글 검사

Data = {'영':'0','일':'1','이':'2','삼':'3','사':'4','오':'5','육':'6','칠':'7','팔':'8','구':'9'}

D = '''\
영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이
'''
for j in range(len(D.splitlines())):
    result=[]
    check=''
    for i in range(len(D.splitlines()[j])):
        if D.splitlines()[j][i] in Data.keys():
            result.append(Data[D.splitlines()[j][i]])
        elif D.splitlines()[j][i] in Data.values():
            result.append(D.splitlines()[j][i])

    for k in range(0,3):
        check += result[k]
    if check =='010' and len(result)==11:
        print('True')
    elif check !='010':
        if len(result) == 10 or len(result) ==11:
            print('True')
        else:
            print('false')
    else:
        print('false')    
    print(result)

2018/12/01 14:19

S.H

ph = list(input())
x = {'영':0, '일':1, '이':2, '삼':3, '사':4, '오':5, '육':6, '칠':7, '팔':8, '구':9}
def ph_to_num(ph):
    result = []
    for i in ph:
        if i.isdigit():
            result.append(i)
        else:
            a = str(x.get(i,10))
            if a == '10':
                continue
            else:
                result.append(a)
    if len(result) == 11 and result[2] == 0:
        return ''.join(result), True
    elif (len(result) == 10 or len(result) == 11) and result[2] != 0:
        return ''.join(result), True
    else:
        return ''.join(result), False

print(ph_to_num(ph))

2019/01/23 10:26

D.H.

def check_phone(str):
    dict = {'영':'0', '일':'1', '이':'2', '삼':'3', '사':'4', '오':'5', '육':'6', '칠':'7', '팔':'8', '구':'9'}
    lis = list(str)
    conv = []
    for i in lis:
        if i in dict.keys():
            conv.append(dict[i])
        elif i in dict.values():
            conv.append(i)

    print("".join(conv), end=' ' )
    if len(conv) == 11  and conv[0]+conv[1] == '01' and conv[2] in dict.values():
        return True
    return False


print(check_phone("영일영-구구칠8-일구팔사"))

2019/03/02 13:38

얀차

namespace codingdojang__
{
    class Program
    {
        static void Main(string[] args)
        {
            Number("영일영 - 구구칠8 - 일구팔사");
            Number("0일영.칠칠칠팔.이삼사");
            Number("영 일 칠 삼 칠 오 팔 이 팔 이");
            Number("영일일 34구구 4 오 9 이");
        }

        static void Number(string n)
        {
            n = n.Replace(" ", "");
            n = n.Replace("-", "");
            n = n.Replace(".", "");
            string number = "";
            string temp = "";
            Dictionary<string, string> convert = new Dictionary<string, string> { { "영", "0" }, { "일", "1" }, { "이", "2" }, { "삼", "3" },
                { "사", "4" }, { "오", "5" }, { "육", "6" }, { "칠", "7" }, { "팔", "8" }, { "구", "9" } };
            for (int i = 0; i < n.Length; i++)
            {
                try
                {
                    int.Parse(n[i].ToString());
                    temp = n[i].ToString();
                }
                catch
                {
                    temp = convert[n[i].ToString()];
                }
                number += temp;
            }
            Console.WriteLine(number);
            string length = number[0].ToString() + number[1].ToString() + number[2].ToString();
            if (length == "010" && number.Length == 11)
            {
                Console.WriteLine(true);
            }
            else if (int.Parse(length) < 020 && int.Parse(length) > 010)
            {
                if(number.Length == 11 || number.Length == 10)
                {
                    Console.WriteLine(true);
                }
            }
            else
            {
                Console.WriteLine(false);
            }
        }
    }
}

2019/03/31 13:04

bat

public class 폰번게시글검사 {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        String[] nums = str.split("");
        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<nums.length; i++) {
            switch(nums[i]) {
            case "영":
            case "0":
                list.add(0);
                break;
            case "1":   
            case "일":
                list.add(1);
                break;
            case "이":
            case "2":
                list.add(2);
                break;
            case "삼":
            case "3":
                list.add(3);
                break;
            case "사":
            case "4":
                list.add(4);
                break;
            case "오":
            case "5":
                list.add(5);
                break;
            case "육":
            case "6":
                list.add(6);
                break;
            case "칠":
            case "7":
                list.add(7);
                break;
            case "팔":
            case "8":
                list.add(8);
                break;
            case "구":
            case "9":
                list.add(9);
                break;
            default:
            }
        }
        String number = list.stream().map(Object::toString).collect(Collectors.joining(""));
        if(list.get(2)==0) {
            if(list.size()==11) {
                System.out.print(number+" ");
                System.out.println(true);
            }
            else {
                System.out.print(number+" ");
                System.out.println(false);
            }
        }
        else {
            if(list.size()==10||list.size()==11) {
                System.out.print(number+" ");
                System.out.println(true);
            }
            else {
                System.out.print(number+" ");
                System.out.println(false);
            }
        }
    }
}

2019/12/19 17:41

big Ko

dict={"공":0,"영":0,"일":1,"이":2,"삼":3,"사":4,"오":5,"육":6,"칠":7,"팔":8,"구":9,
"하나":1,"둘":2,"셋":3,"넷":4,"다섯":5,"여섯":6,"일곱":7,"여덟":8,"아홉":9}
lst=list(map(str,input("문자 및 숫자를 입력하십시오: ")))
elst=[]
for n in lst:
    if n in dict:
        elst.append(dict.get(n))
    try:
        elst.append(int(n))
    except:
        continue
pn="".join(list(map(str,elst)))
if pn[:2]!="01":
    print(pn,"False")
elif len(pn)!=10 and len(pn)!=11:
    print(pn,"False")
elif pn[:3]=="010" and len(pn)!=11:
    print(pn,"False")
else:
    print(pn,"True")

2020/01/17 16:29

박시원

num = "영일이삼사오육칠팔구"
dic_num = {'공': '0'}
for n in range(0, 10):
    dic_num[num[n]] = str(n)

def Check(a) :
    phone_num =""
    for n in a :
        for k, v in dic_num.items() :
            if str(n) in (k, v) :
                if str(n) in (k) :
                    phone_num+=dic_num[n]
                else :
                    phone_num+=n
                break

    if phone_num[0:2] == '01':
        if phone_num[2] == '0' and len(phone_num) != 11:
            return print(phone_num + ": false")
        else:
            if len(phone_num) == 10 or len(phone_num) == 11:
                return print(phone_num + ": true")
            else:
                return print(phone_num + ": false")

2020/01/21 19:08

김민규

N = list(input())
checklist = ['영','일','이','삼','사','오','육','칠','팔','구','십']
final = list()
for i in range(len(N)):
    m = 0
    try:
        m = int(N[i])
        final.append(m)
    except ValueError:
        check = -1
        for j in range(len(checklist)):
            if checklist[j] == N[i]:
                check = j
        if check != -1:
            final.append(check)
        elif check == -1:
            pass
for i in final:
    print(i,end = "")
print(" ",end="")
if str(final[0]) + str(final[1]) + str(final[2]) == "010":
    if len(final) == 11:
        print("true")
    else:
        print("false")
else:
    if len(final) == 11 or len(final) == 10:
        print("true")
    else:
        print("false")

2020/03/30 00:56

BlakeLee

def check_num(x):
    num,z='영일이삼사오육칠팔구',[]
    for i in range (len(x)):
        if ord(x[i])>=48 and ord(x[i])<=57:
            z.append(x[i])
        else:
            for j in range(len(num)):
                if num[j]==x[i]:
                    z.append(str(j))
    z=''.join(z)
    print (z,end=' ')
    if (z[:2]=='01' and z[2]=='0') and (len(z)==11):
        print (True)
    elif (z[:2]=='01' and z[2]!='0') and (len(z)==11 or len(z)==10):
        print (True)
    else:
        print (False)

check_num('영일영-구구칠8-일구팔사')
check_num('0일영.칠칠칠팔.이삼사')
check_num('영 일 칠 삼 칠 오 팔 이 팔 이')
check_num('영일일 34구구 4 오 9 이')

2020/05/03 08:13

Buckshot

<결과> 01099781984 True 0107778234 False 0173758282 True 01134994592 True - Buckshot, 2020/05/03 08:13
input_str = '''영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이'''
import re
def conv(inp):
    num = {'영':0, '일':1, '이':2, '삼':3, '사':4, '오':5, '육':6, '칠':7, '팔':8, '구':9}
    c1 = [re.sub('[가-힣]', lambda m: str(num[m.group()]), s) for s in inp]
    for p in [re.sub('[-. ]', '', s) for s in c1]:
        if (p[2] == '0') and (len(p) != 11):
            print(p, 'false')
        else: print(p, 'true')

if __name__ == '__main__':
    inp = input_str.splitlines()
    conv(inp)

2020/05/14 11:01

Hwaseong Nam

정규식 sub함수로 연습 - Hwaseong Nam, 2020/05/14 11:04
num = list(input())
real_num = []
for i in num:
    if i == '0' or i == '영':
        real_num.append('0')
    elif i == '1' or i =='일':
        real_num.append('1')
    elif i == '2' or i == '이':
        real_num.append('2')
    elif i == '3' or i == '삼':
        real_num.append('3')
    elif i == '4' or i == '사':
        real_num.append('4')
    elif i == '5' or i == '오':
        real_num.append('5')
    elif i == '6' or i == '육':
        real_num.append('6')
    elif i == '7' or i == '칠':
        real_num.append('7')
    elif i == '8' or i == '팔':
        real_num.append('8')
    elif i == '9' or i == '구':
        real_num.append('9')
    else:
        continue
if len(real_num) != 11:
    print(real_num, 'False')
else:
    print(real_num, "True")

2020/07/02 13:39

Money_Coding

def phoneN(s):
    han = ["영", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구"]
    num = [str(i) for i in range(10)]
    s = s.replace('-', '').replace('.', '').replace(' ', '')
    for k in range(10):
        s = s.replace(han[k], num[k])
    if s[0:3] == "010" and len(s) != 11:
        print(s, False)
    else:
        print(s, True)


phoneN("영일영-구구칠8-일구팔사")
phoneN("0일영.칠칠칠팔.이삼사")
phoneN("영 일 칠 삼 칠 오 팔 이 팔 이")
phoneN("영일일 34구구 4 오 9 이")

2020/12/02 15:26

김우석

const input=prompt('입력','').trim();
    const trimInput=input.split('')
    let tfCheck=false;

    const check=/[0-9,가-힣]/;
    const numCheck=/[0-9]/;

    const phNum=trimInput.filter((el)=>check.test(el));

    const numberStr=phNum.map((el)=>{
        el=(numCheck.test(el))?el:change(el)

        return el;
    })
    console.log(numberStr)

    let result=numberStr.join('');

    if(result.substring(0,3)=='011'||result.substring(0,3)=='012'||result.substring(0,3)=='013'||result.substring(0,3)=='014'||result.substring(0,3)=='015'||result.substring(0,3)=='016'||result.substring(0,3)=='017'||result.substring(0,3)=='018'||result.substring(0,3)=='019'){
        if(result.length==10){
            tfCheck=true;       
        }
    }
    else{
        if(result.length==11){
            tfCheck=true;
        }
    }

    console.log(tfCheck)
function change(el){
    const korean=['영','일','이','삼','사','오','육','칠','팔','구'];

    for (let i =0; i < 10; i++) {
        if(el==korean[i]){
            el=String(i)
            break;
        }   
    }
    (numCheck.test(el))?el:'';
    return el;
}

2021/02/10 11:27

wldus

#codingdojing_phone number check

korean = '영일이삼사오육칠팔구'
num_str = '0123456789'
old_num = ['0' + str(x) for x in range(11,20)]

def phone_num(num: str):

    new_n = ''
    flag = True

    for s in num:
        if s in korean:
            new_n += str(korean.find(s))
        elif s in num_str:
            new_n += str(num_str.find(s))
        else:
            new_n += ''

    if new_n[:3] == '010' and len(new_n) == 11:
        flag = True
    elif new_n[:3] in old_num and len(new_n) in [10, 11]:
        flag = True
    else:
        flag = False

    print(new_n, flag)

phone_num('영일영-구구칠8-일구팔사')
phone_num('0일영.칠칠칠팔.이삼사')
phone_num('영 일 칠 삼 칠 오 팔 이 팔 이')
phone_num('영일일 34구구 4 오 9 이')

2021/10/20 11:24

Jaeman Lee

def check_phone_number(a):
    e = {'영':'0', '일':'1', '이':'2', '삼':'3', '사':'4', '오':'5', '육':'6', '칠':'7', '팔':'8', '구':'9'}
    c = []
    for i in a:
        if i in e.keys():
            c.append(e[i])
        elif i in e.values():
            c.append(i)
    print(" ".join(c),end=' ')
    if len(c) == 11 and c[0]+c[1] == '01' and c[2] in e.values():
        return True
    elif len(c) == 10 and c[0]+c[1] == '01' and c[2] in e.values():
        return True
    return False

a = "영일일 34구구 4 오 9 이"
print(check_phone_number(list(a)))

2021/11/09 19:22

서현준


# 폰번 게시글 검사

def Change(data):
    strings_dic = dict(zip('영일이삼사오육칠팔구','0123456789')) 
    result =""
    for i in data: 
        if i in strings_dic.keys():
            result = result + strings_dic[i]
        else:
            result = result + i
    return result

def PhoneNumber(data):
    value = " "
    value = Change(data)
    if value[:3] in ['0'+ str(i) for i in range(11,20)] and len(data) >= 10 and len(data) <=11 :
        print(value)
    elif value[:3] == '010' and len(data) == 11:
        print(value)
    else:
        print("오류")
        False 


PhoneNumber("영1일일팔구이팔90")
PhoneNumber("영1영영일팔구이팔90")

2021/12/25 12:40

semipooh

a =input("휴대폰 번호 입력")

dic={'영':0,'일':1,'이':2,'삼':3,'사':4,'오':5,'육':6,'칠':7,'팔':8,'구':9}

arr = []
for i in a :   
    try :
        arr.append(dic[i])
    except KeyError:
        try :
            arr.append(int(i))
        except ValueError:
            pass
print("".join(list(map(str,arr))),end =" ")
if arr[2]==0 : 
    if len(arr)==11:
        print("True")
    else: 
        print("False")
else :
    if len(arr)==10 or len(arr)==11:
        print("True")
    else: 
        print("False")

1.특수기호 제외

2.모두 숫자화

3. 010 구분하여 번호검사 알고리즘 분리

이 순서로 짜봤어요~ 1번 2번은 예외처리 함수를 활용했어요( 숫자를 제외한 문자를 int화 시켰을떄 Err가 나는걸 이용)

2022/01/18 02:16

양캠부부

inp = '''영일영-구구칠8-일구팔사
0일영.칠칠칠팔.이삼사
영 일 칠 삼 칠 오 팔 이 팔 이
영일일 34구구 4 오 9 이'''

kor ='영일이삼사오육칠팔구'

def convert(nl): #en: extract number
    nl_pre = list(nl.replace(' ','').replace('.','').replace('-',''))
    for i,alp in enumerate(nl_pre):
        if alp in kor:
            nl_pre[i] = str(kor.index(alp))
    return ''.join(nl_pre)

def judge(n):
    if len(n) == 11 and n[:3] == '010': return True
    elif len(n) == 10 and n[:2] == '01': return True
    else : return False

nls = number_lists = inp.splitlines()
for nl in nls:
    print(convert(nl), judge(convert(nl)))

2022/02/19 13:21

로만가

package org.javaturotials.ex;
import java.util.*;
import java.util.stream.Collectors;

public class test {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        String first ="";
        int count=0;
        String phone = sc.nextLine();
        String re = phone.replaceAll("[.]", "").replaceAll("[-]", "").replaceAll(" ", "").replaceAll("영", "0").replaceAll("일", "1").replaceAll("이", "2").replaceAll("삼", "3").replaceAll("사", "4").replaceAll("오", "5").replaceAll("육", "6").replaceAll("칠", "7").replaceAll("팔", "8").replaceAll("구", "9");
        for(int j=0; j<3; j++) {
         first+=re.charAt(j);
    }
        if((first.equals("010") && re.length()==11)||((first.equals("011")||first.equals("012")||first.equals("013")||first.equals("014")||first.equals("015")||first.equals("016")||first.equals("017")||first.equals("018")||first.equals("019"))&&(re.length()==10 || re.length()==11))){
            System.out.println("true");
        }
        else {
            System.out.println("false");
        }
    }
    }

2022/02/23 16:15

Kkubuck

using System;
using System.Collections.Generic;

namespace solution
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "영일영-구구칠8-일구팔사";

            Console.WriteLine(" :  {0}", isPhoneNumber(input));
            Console.WriteLine(" :  {0}", isPhoneNumber("0일영.칠칠칠팔.이삼사"));
            Console.WriteLine(" :  {0}", isPhoneNumber("영 일 칠 삼 칠 오 팔 이 팔 이"));
            Console.WriteLine(" :  {0}", isPhoneNumber("영일일 34구구 4 오 9 이"));
        }

        private static bool isPhoneNumber(string input)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>()
            {
                { "영", "0" }, {"일", "1" }, {"이", "2" }, {"삼", "3" }, {"사", "4" }, {"오", "5" },
                { "육", "6" }, {"칠", "7" }, {"팔", "8" }, {"구", "9"}
            };

            string pNum = "";
            for (int i = 0; i < input.Length; i++)
            {
                if (dic.ContainsKey(input[i].ToString()))
                    pNum += dic[input[i].ToString()];
                else if (char.IsDigit(input[i]))
                    pNum += input[i];
            }
            Console.Write("  {0,11}",pNum);

            int aCode = int.Parse(pNum.Substring(0, 3));
            if (aCode == 10 && pNum.Length == 11)
                return true;
            else if (11 <= aCode && aCode <= 19 && (pNum.Length == 10 || pNum.Length == 11))
                return true;
            else
                return false;
        }
    }
}

2023/08/29 20:28

insperChoi

목록으로