๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜/Programmers

[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 7์ผ์ฐจ ๋ฌธ์ œ

728x90

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค C++

 

ํŠน์ • ๋ฌธ์ž ์ œ๊ฑฐํ•˜๊ธฐ

string solution(string my_string, string letter) {
    string answer = "";
    answer = regex_replace(my_string, regex(letter), "");
    return answer;
}

๊ฐ๋„๊ธฐ

int solution(int angle) {
    if(angle==90) return 2;
    if(angle == 180) return 4;
    if(angle>0 && angle<90) return 1;
    return 3;
}

์–‘๊ผฌ์น˜

int solution(int n, int k) {
    int ten = n/10;
    k -= ten;
    int answer = n*12000 + k*2000;
    return answer;
}

์ง์ˆ˜์˜ ํ•ฉ

for(int i=1; i<=n; ++i){
    if(i%2) continue;
    answer += i;
}

// or

for(int i=0; i<=n; i+=2){
		answer += i;
}

→ ์ƒˆ๋กœ์šด ํ’€์ด๋ฐฉ๋ฒ•

int answer = n/2;
    answer *= answer + 1;
// ์ฃผ์–ด์ง„ ์ˆซ์ž์˜ '์ค‘๊ฐ„๊ฐ’'๊ณผ ๊ทธ '์ค‘๊ฐ„๊ฐ’+1'์˜ ๊ฐ’์„ ๊ณฑํ•˜๋ฉด ์ง์ˆ˜์˜ ํ•ฉ์ด๋‹ค

 

 

โœ๐Ÿป ๋ฌธ์ž์—ด์˜ ๋‚ด์šฉ ์น˜ํ™˜ 1. #include <regex> ํ›„ regex_replace(my_string, regex(letter), "") → ๋ฌธ์ž์—ด์—์„œ letter ๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ๊ฒ€์ƒ‰ ํ›„ ์‚ญ์ œ 2. my_string.replace(0, 2, ””) → ๋ฌธ์ž์—ด์˜ ์ธ๋ฑ์Šค 0๋ถ€ํ„ฐ, 2๊ธ€์ž๋ฅผ ์‚ญ์ œ

 

โœ๐Ÿป ์ฃผ์–ด์ง„ ์ˆซ์ž๋ฅผ 2๋กœ ๋‚˜๋ˆˆ '์ค‘๊ฐ„๊ฐ’'๊ณผ ๊ทธ '์ค‘๊ฐ„๊ฐ’+1'์˜ ๊ฐ’์„ ๊ณฑํ•˜๋ฉด, ์ฃผ์–ด์ง„ ์ˆซ์ž ์ดํ•˜์˜ ๋ชจ๋“  ์ง์ˆ˜๋“ค์˜ ํ•ฉ์ด ๋œ๋‹ค.

728x90