竞赛
考级
法兰西玫瑰
利用i j 去模拟题目
海螺
KFCKUN
使用临时字符串记录每一个数最后更新一下就行
队团加不)ด้้童帅_者仇复
#include<bits/stdc++.h> using namespace std; int main() { string s; int n; cin >> s >> n; while (n--) { string t; for (int i = 0; i < s.size();) { int j = i; while (j < s.size() && s[j] == s[i]) j++; int cnt = j - i; t += (to_string(cnt) + s[i]); i = j; } s = t; } cout << s <<endl; }
啊?
//截取字符串并返回一个字符串 static string str_shu(string s,int n) { string result = ""; int count = 1; string s1 = ""; for (int i = 1; i < s.size(); i++){ if (s[i] == s[i - 1]) { count++; }else { s1 += count + '0'; // 将数字转换成字符 s1 += s[i - 1]; // 拼接字符串 count = 1; } } s1 += count + '0'; s1 += s[s.size() - 1]; result = s1; if (n == 1){ return result; } return str_shu(result,--n); }
191****0079
#include<iostream> using namespace std; int main() { string s; int n; cin >> s >> n; while (n--) { string t; for (int i = 0; i < s.size();) { int j = i; while (j < s.size() && s[j] == s[i]) j++; int cnt = j - i; t += (to_string(cnt) + s[i]); i = j; } s = t; } cout << s <<endl; }
hhh
#include <bits/stdc++.h> using namespace std; string s; int n; void work() { cin>>s; cin>>n; while(n--) { string s1=""; int ans=1; for(int i=1;i<s.size();i++) { if(s[i]==s[i-1]) ans++; else { s1+=ans+'0'; s1+=s[i-1]; ans=1; } } s1+=ans+'0'; s1+=s[s.size()-1]; s=s1; } cout<<s; } int main() { work(); return 0; }
Voldemort
准
majmDZB
我过关! 代码:
最新热门小游戏🔞acgo.cn
题解 #include <bits/stdc++.h> using namespace std; string s,ans; int t,len; int main() { cin>>s; cin>>t; while(t--) { len = s.size(); ans=""; for(int i=0;i<=len-1;i) { int j = i+1,cnt=1; while(s[i]==s[j]) j,cnt++; ans+=cnt+'0'; ans+=s[i]; i=j-1; } s=ans; } cout<<s<<endl; }
一个屑水作
#include <bits/stdc++.h> using namespace std; string s,ans; int t,len; int main(){ cin>>s>>t; while(t--){ len = s.size(); ans=""; for(int i=0;i<=len-1;i++){ int j =i+1,cnt=1; while(s[i]==s[j]){ j++; cnt++; } ans+=cnt+'0'; ans+=s[i]; i=j-1; } s=ans; } cout<<s<<endl; return 0; }
qwerty1596