"프로그래머스 120904 숫자 찾기"의 두 판 사이의 차이

(새 문서: ==개요== {{프로그래머스|레벨=0|페이지=7}} ==C++== <syntaxhighlight lang='cpp'> #include <string> #include <vector> using namespace std; int solution(int num, int k) {...)
 
 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
{{프로그래머스|레벨=0|페이지=7}}
{{프로그래머스|레벨=0|페이지=7|분류=코딩테스트 입문}}
[[분류: 프로그래머스 입문 캘린더]]
* [[프로그래머스 입문 캘린더]]


==C++==
==C++==

2023년 11월 26일 (일) 12:51 기준 최신판

1 개요[ | ]

프로그래머스 120904 숫자 찾기

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

int solution(int num, int k) {
    string str = to_string(num);
    int len = str.length();
    for(int i=0; i<len; i++) {
        if(str[i] == '0'+k) {
            return i+1;            
        }
    }
    return -1;
}