-
[Algorithm] ์๊ณ ๋ฆฌ์ฆ ํ ์ ๋ฆฌ (C++)Algorithm 2022. 1. 5. 10:43
1. auto
list<char> l; string word; cin >> word; for (auto c: word) { l.push_back(c); // word์ ์ ๋ ฅ๋ ๋จ์ด๋ฅผ ํ๋ํ๋ l์ ๋ฃ๋๋ค. } for (auto c: l) cout << c; // l์ ๋ชจ๋ ์์ ์ถ๋ ฅ // ์ ๋ ฅ Hello // ์ถ๋ ฅ HelloHello ์ ๋ ฅ ๋ฐ์ผ๋ฉด, H e l l o ๋ฅผ ์ฐจ๋ก๋๋ก list์ ๋ฃ๊ณ , ๋ง์ง๋ง์ Hello๋ฅผ ์ถ๋ ฅํ๋ค.
2.
list<char> l; string word; cin >> word; for (auto c: word) { l.push_back(c); // word์ ์ ๋ ฅ๋ ๋จ์ด๋ฅผ ํ๋ํ๋ l์ ๋ฃ๋๋ค. } for (auto i = l.begin(); i != l.end(); i++) { cout << *i << "\n"; } ์ ๋ ฅ Hello ์ถ๋ ฅ H e l l o3. ๊ฑฐ๊พธ๋ก ์ถ๋ ฅ
list<char> l; string word; cin >> word; for (auto c: word) { l.push_back(c); // word์ ์ ๋ ฅ๋ ๋จ์ด๋ฅผ ํ๋ํ๋ l์ ๋ฃ๋๋ค. } for (auto i = l.rbegin(); i != l.rend(); i++) { cout << *i << "\n"; } // ์ ๋ ฅ Hello // ์ถ๋ ฅ o l l e H4. set ์ฌ์ ์ญ์์ผ๋ก ์ถ๋ ฅ. set์ ์๋์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ๋ผ. map๋ ๋ง์ฐฌ๊ฐ์ง.
// ์ฌ๊ธฐ์ se๋ set. ์งํฉ. for (auto i = se.rbegin(); i != se.rend(); i++) { // ์ฌ์ ์ญ์์ผ๋ก ์ถ๋ ฅ cout << *i << "\n"; }๊ณต๋ฐฑ์ ํฌํจํ ๋ฌธ์์ด ์ ๋ ฅ ๋ฐ๊ธฐ
// ๊ณต๋ฐฑ์ ํฌํจํ ๋ฌธ์์ด ์ ๋ ฅ๋ฐ๊ธฐ string s; getline(cin, s); cout << s;์ ๋ ฅ ๋ฐ์ ๊ทธ๋๋ก ์ถ๋ ฅํ๊ธฐ (์ ๋ ฅ์ ๋์ ๋ชจ๋ฅผ ๋)
#include <iostream> #include <algorithm> #include <string> using namespace std; string s; int main(void) { cin.tie(0); cout.tie(0); std::ios::sync_with_stdio(false); while (getline(cin, s)) { cout << s << "\n"; } return 0; }'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Algorithm] ๋ฐฑ์ค 1157 ๋จ์ด ๊ณต๋ถ (Swift/C++) (0) 2022.01.31 [Algorithm] ๋ฐฑ์ค 10809 ์ํ๋ฒณ ์ฐพ๊ธฐ(Swift/C++) (0) 2022.01.30 [Algorithm] ๋ฐฑ์ค 11654 ์์คํค์ฝ๋ (Swift/C++) (0) 2022.01.30 [Algorithm] ์๊ฐ ๋ณต์ก๋ & ๊ณต๊ฐ ๋ณต์ก๋ (0) 2022.01.12 [Algorithm] ์๊ณ ๋ฆฌ์ฆ ํ ์ ๋ฆฌ (Swift) (0) 2022.01.05