結果

問題 No.996 Phnom Penh
ユーザー LCA_Trim
提出日時 2020-02-21 23:18:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 951 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 90,460 KB
実行使用メモリ 13,632 KB
最終ジャッジ日時 2024-10-09 02:20:43
合計ジャッジ時間 4,667 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iostream>
#include <deque>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
	string str;
	cin >> str;

	long long count = 0;

	while (true)
	{
		auto pos = str.find("phnom");
		if (pos != string::npos)
		{
			str = str.substr(0, pos) + "penh" + str.substr(pos + 5);
			++count;
		}
		else
		{
			bool isChanged = false;
			while (true)
			{
				auto pos = str.find_first_of("h");

				if (pos == string::npos)
				{
					break;
				}

				isChanged = true;
				if (pos == str.size() + 1)
				{
					str = str.substr(0, pos);
				}
				else
				{
					str = str.substr(0, pos) + str.substr(pos + 1);
				}
			}

			for(char& c: str)
			{
				if (c == 'e')
				{
					c = 'h';
					isChanged = true;
				}
			}

			if (!isChanged)
			{
				break;
			}
			++count;
		}
	}
	cout << count << endl;
}
0