-
[C++] ๋ฐฑ์ค 9935๋ฒ. ๋ฌธ์์ด ํญ๋ฐ์ฝ๋ฉํ ์คํธ/์ฝ๋ฉํ ์คํธ ์ฐ์ต 2020. 10. 27. 18:13728x90
#include<iostream> #include<string> using namespace std; int main() { string s1, s2; getline(cin, s1); getline(cin, s2); int size = s2.size(); int idx = 0; while (s1.find(s2) != std::string::npos) { int index = s1.find(s2, idx); //s1 = s1.substr(0, index) + s1.substr(index + size, s1.size()); s1.erase(index, size); idx = index - size; if (idx < 0) idx = 0; } if (s1.empty()) cout << "FRULA" << endl; else cout << s1 << endl; return 0; }
๋จ์ํ๊ฒ ๋ฌธ์์ด ํ์์ผ๋ก ํ์๋ค๊ฐ ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ๋ค.
์ต์ํ์ ํ์์ ํ๊ธฐ ์ํด string์ ์คํ์ฒ๋ผ ์ฌ์ฉํ๋ค.
#include<iostream> #include<string> using namespace std; int main() { string s1, s2; cin >> s1 >> s2; string s3 = ""; int size = s2.size(); for (int i = 0; i < s1.size(); i++) { s3.push_back(s1[i]); if (s3.back() == s2.back()) { bool check = true; for (int j = 1; j <= size; j++) { if (s3[s3.size() - j] != s2[s2.size() - j]) check = false; } if (check) { for (int j = 0; j < size; j++) s3.pop_back(); } } } if (s3.empty()) cout << "FRULA" << endl; else cout << s3 << endl; return 0; }
728x90'์ฝ๋ฉํ ์คํธ > ์ฝ๋ฉํ ์คํธ ์ฐ์ต' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[C++] ์ผ์ฑ 1952. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์์์ฅ (0) 2020.10.27 [C++] ์ผ์ฑ 2382. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ๋ฏธ์๋ฌผ ๊ฒฉ๋ฆฌ (0) 2020.10.27 [C++] ์ผ์ฑ 2383. [๋ชจ์ SW ์ญ๋ํ ์คํธ] ์ ์ฌ ์์ฌ์๊ฐ (0) 2020.10.27 [C++] ํ๋ก๊ทธ๋๋จธ์ค ์ฌ ์ฐ๊ฒฐํ๊ธฐ (0) 2020.10.27 [C++] ํ๋ก๊ทธ๋๋จธ์ค ๋จ์ด ๋ณํ (0) 2020.10.27