"프로그래머스 181873 특정한 문자를 대문자로 바꾸기"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
{{프로그래머스|레벨=0|페이지=4}}
{{프로그래머스|레벨=0|페이지=4}}
[[분류: 대소문자]]
[[분류: 코딩테스트 대소문자]]


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

2023년 9월 17일 (일) 17:19 판

1 개요

프로그래머스 181873 특정한 문자를 대문자로 바꾸기

2 C++

#include <string>
#include <vector>

using namespace std;

string solution(string my_string, string alp) {
    for(auto& ch: my_string) {
        if(ch == alp[0]) {
            ch -= 32;
        }
    }
    return my_string;
}
#include <string>
#include <vector>

using namespace std;

string solution(string my_string, string alp) {
    for(int i=0; i<my_string.length(); i++) {
        if(my_string[i] == alp[0]) {
            my_string[i] = toupper(alp[0]);
        }
    }
    return my_string;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}