: string, ์คํ
: ๋ง์ฝ์ ํ์๋ฆฌ ์๊ฐ ์๋ค๊ณ ์ฐจ๋ฉด
๋ด๊ฐ ๋ง๋ ํ๋ก์ธ์ค๋ ๋์์ด ์๋จ.
mirkovC4nizCC44
m
์๋ชป๋ ๋ถ๋ถ
ํ์๋ฆฌ์ธ ๊ฒ์ ์บ์น๋ฅผ ํ๋ค๋ฉด, ์ด๋ ๊ฒ ์์ฑํ์ง๋ ์์์ ๊ฒ์.
#include <iostream>
using namespace std;
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <stack>
// 02:00 ~
// ๋ฌธ์์ด ํญ๋ฐ
int main()
{
// ๋จ์ ๋ฌธ์์ด์ ์ด์ด๋ถ์.
// ๋ฌธ์์ด์ ๊ธธ์ด๋ ๋ฐฑ๋ง ์ดํ์.
string target;
cin >> target;
string s;
cin >> s;
// s์ back์ด๋ ํ๋์ iter๊ฐ ๋์ผ ํ๋ค๋ฉด
// s์ ๋ฌธ์์ด๋งํผ ์์ผ๋ก ์ด๋ํ๋ฉด์ ๋น๊ต๋ฅผ ํ์.
// 12ab112ab
// 11ab ๋ผ๋ฉด?
// temp ๋ณ์์๋ค๊ฐ ์ ์ฅํด๋๊ณ ,
// ๋ฆฌ๋ฒ์ค ํด์ ๋ค์ ๋ฐํ?
// ์คํ์ ํด๋ณด์์ผ ํ ๋ฏํจ.
stack<char>stk;
for (int i = 0; i < target.length(); ++i)
{
// ๋งค์นญ๋์ง ์์ ๊ฒฝ์ฐ๋ฅผ ๋๋นํจ.
string temp = "";
if (!stk.empty() && target[i] == s.back())
{
// ์คํ์ ์์ฌ ์๋ ๊ฑฐ๋ ํ์ธํ๊ธฐ
bool check = false;
for (int j = s.length() - 2; j >= 0; --j)
{
if (stk.top() == s[j])
{
temp += stk.top();
stk.pop();
}
else
{
//ํ๋๋ผ๋ ์ด๊ธ ๋๋ฉด ๋ถ์ผ์น ํ๋ค๋ ๊ฒ์.
check = true;
// ์คํ์์ ๋บ ๊ฒ ๋งํผ์
// ๋ฆฌ๋ฒ์คํด์ ๋ค์ pushํ์.
reverse(temp.begin(), temp.end());
for (int a = 0; a < temp.length(); ++a)
{
stk.push(temp[a]);
}
break;
}
}
// ๋งค์นญ์ด ๋ ๊ฒฝ์ฐ, ๋ฐ์ ํธ์ฌ ์ํ๊ณ , ๋ค์์์๋ก ์งํํ๊ธฐ
if(check == false)
continue;
}
stk.push(target[i]);
}
string res = "";
while (!stk.empty())
{
res += stk.top();
stk.pop();
}
if (res.empty())
{
cout << "FRULA";
return 0;
}
reverse(res.begin(), res.end());
cout << res;
}
: ์๋ํ๋ฉด ๋ฌธ์์ด ๊ธธ์ด 100๋ง ๊น์ง์ด๋ฏ๋ก
: ์ง์ ์ง์ด์ , ๋ฌธ์์ด์ ์ง์ฐ๋ ๋ฌธ์ ์.
: ํ๊ฒ์ ๊ฐฏ์๋งํผ์ ์คํ์์ ํ์ ํ ๊ฒ์ด๋ฏ๋ก,
ํ๊ฒ์ ์ฌ์ด์ฆ์ ๋์ผํ๊ฑฐ๋ ํฐ ์ง๋ฅผ ํ์ธํด์ผ ํจ.
https://velog.io/@kwt0124/%ED%8F%AD%EB%B0%9C-%EC%A7%9D%EC%A7%93%EA%B8%B0-%EB%AC%B8%EC%A0%9C
: ์๊ฐ ์ด๊ณผ ๋ฐ์ํจ.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
string s;
cin >> s;
string target;
cin >> target;
int idx = 0;
// ํ๊ฒ ๋ชป์ฐพ์ ๊ฒฝ์ฐ ๋ฐ์ณ๋์ด.
while (s.find(target) != string::npos)
{
auto iter = s.find(target); //๋ฐ๊ฒฌ๋ ์ธ๋ฑ์ค๋ฅผ ๋ํ๋.
//cout << "์ฐพ์." << iter << endl;
string ss = s.substr(0, iter);
int next = ss.length() + target.length();
s = ss + s.substr(next);
//cout << s << endl;
}
//cout << "result : " << endl;
if (s.empty())
{
cout << "FURLA";
}
else
cout << s;
}
-> ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ํ์ด์ผ ํจ.
๊ทธ๋ฆฌ๋ ํ์ง ๋ชปํ์.
find๋ฅผ ํ ๋๋ง๋ค n์ ๋น์ฉ์ผ๋ก ์ฐพ๊ฒ ๋๋ฏ๋ก ๋ฌธ์ ์.
https://rein.kr/blog/archives/373
: ์ข์ง ๋ชปํ ๋ฏ ํจ.
์ฐธ๊ณ ์๋ฃ : ์น์ด๋จน๋ c++
https://modoocode.com/240
์ฝ๋ : ์ค์ํจ!
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
std::string s = "This is an example";
std::cout << s << '\n';
// erase
// 1๋ฒ : size_t start ~ size_t end ๋ถ๋ถ๊น์ง์ ์ธ๋ฑ์ค๋ฅผ
// ๋ถ๋ถ๋ง์ ์ง์!
s.erase(0, 5); // Erase "This "
std::cout << s << '\n';
//std::find ํจ์๋ iterator๋ฅผ ๋ฐํํจ.
s.erase(std::find(s.begin(), s.end(), ' ')); // Erase ' '
std::cout << s << '\n';
// string.find ํจ์๋
s.erase(s.find("pl")); // Trim from ' ' to the end of the string
std::cout << s << '\n';
s.erase(7);
cout << s << endl;
auto iter = s.find(' ');
//s.erase(s.find(' ')); // Trim from ' ' to the end of the string
s.erase(iter); // Trim from ' ' to the end of the string
std::cout << s << '\n';
}
-> ๋๋ ์ . erase ์ ์ธ์๋ก ์ฌ์ฉ๋๋ ๊ฒ๋ค์ ๋ฐ๋ผ์ ์ง์์ง๋ ๋ฐฉ์์ด
๋ชจ๋ ๋ค๋ฆ.