L1-058 6翻了

题目 L1-058 6翻了

image-03239208

思路分析

image-98d75182

代码实现

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'

using ll = long long;

using ull = unsigned long long;

using PII = pair<int,int>;

using Pll = pair<ll,ll>;

int dx[4]= {-1,0,1,0},dy[4]= {0,1,0,-1};

const int inf = 0x3f3f3f3f;

int main() {

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	string s;

	getline(cin,s);

	string result;

	int i=0;

	while (i < s.size()) {

		if(s[i]=='6') {

			int j = i;

			while (j < s.size() && s[j] == '6') j++;

			int len = j - i;

			if (len > 9) {

				result += "27";

			} else if (len > 3) {

				result += "9";

			} else {

				result += string(len, '6');

			}

			i = j;

		} else {

			result += s[i];

			i++;

		}

	}

	cout << result << '\n';

	return 0;

}

同类题型

视频讲解


⬅️ L1-057 PTA使我精神焕发 🏠 00-天梯赛 ➡️ L1-059 敲笨钟