๐ ๊ณต๋ถํ๋ ์ง์ง์ํ์นด๋ ์ฒ์์ด์ง?
[Programmers C++] ์ฝ๋ฉ ๊ธฐ์ด ํธ๋ ์ด๋ - ๋์๋ฌธ์ ๋ฐ๊ฟ์ ์ถ๋ ฅํ๊ธฐ ๋ณธ๋ฌธ
๐ฆฅ ์ฝํ
/Programmers
[Programmers C++] ์ฝ๋ฉ ๊ธฐ์ด ํธ๋ ์ด๋ - ๋์๋ฌธ์ ๋ฐ๊ฟ์ ์ถ๋ ฅํ๊ธฐ
์ง์ง์ํ์นด 2023. 6. 1. 18:31728x90
๋ฐ์ํ
์์ด ์ํ๋ฒณ์ผ๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด str์ด ์ฃผ์ด์ง๋๋ค.
๊ฐ ์ํ๋ฒณ์ ๋๋ฌธ์๋ ์๋ฌธ์๋ก, ์๋ฌธ์๋ ๋๋ฌธ์๋ก ๋ณํํด์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์.
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string str;
cin >> str;
// & : ์ฐธ์กฐ(reference) ํ์
// ํด๋น ๋ณ์๋ฅผ ๋ณต์ฌํ์ง ์๊ณ ๊ฐ์ ๋ณ๊ฒฝ
for (char& c : str) {
// ๋๋ฌธ์์ธ์ง ํ๋ณ
if (isupper(c)) {
// ๋๋ฌธ์๋ฅผ ์๋ฌธ์๋ก ๋ณํ
c = tolower(c);
// ์๋ฌธ์์ธ์ง ํ๋ณ
} else if (islower(c)) {
// ์๋ฌธ์๋ฅผ ๋๋ฌธ์๋ก ๋ณํ
c = toupper(c);
}
}
cout << str << endl;
return 0;
}
728x90
๋ฐ์ํ
'๐ฆฅ ์ฝํ > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments