import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.next();
char[] array = s.toCharArray();
StringBuilder sb = new StringBuilder();
int count = 1;
if (array.length == 0) {
System.out.print("null");
}
if (array.length == 1) {
System.out.print("" + count + array[0]);
}
for (int i = 1; i < array.length; i++) {
if (array[i] == array[i - 1]) {
count++;
} else {
sb.append(count).append(array[i - 1]);
count = 1;
}
if (i == array.length - 1) {
sb.append(count).append(array[i]);
}
}
System.out.print(sb.toString());
}
}
#include <iostream>
#include <string>
using namespace std;
//将数字字符串格式转换为原来字符串中出现的字符+该字符连续出现的次数的字符串P231
string func(string str){
string ret;
int len=str.length();
for (int i=0;i<len;i++)
{
//当是连续字符时,跳过并将计数加一
int count=1;
while (str[i]==str[i+1])
{
count++;
i++;
}
//统计连续出现的字符及出现的次数到结果字符串
char tmp[10];
sprintf(tmp,"%d",count);//代替itoa使用,sprintf_s存在版本问题
ret+=tmp;
ret+=str[i];
}
return ret;
}
int main(){
string str;
cin>>str;
cout << func(str) << endl;
return 0;
}
var readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', function (input) {
var str = input
function convert(str){
var ans = ''
for (var i=0; i< str.length; i++){
if (str[i] === str[i+1]){
var sum = 1
while (str[i] === str[i+1]){
i++
sum++
}
ans += '' + sum + str[i]
}else {
ans += '' + 1 + str[i]
}
}
return ans
}
console.log(convert(str))
});
#include <cstdio>
#include <cstring>
#include <algorithm>
usingnamespacestd;
chars[10010];
intmain() {
scanf("%s", s+1);
intcnt = 0;
charch = s[1];
s[0] = s[1];
for(inti = 1; s[i]; i++) {
if(s[i] == s[i-1]) cnt++;
else{
printf("%d%c", cnt, ch);
cnt = 1;
ch = s[i];
}
}
printf("%d%c", cnt, ch);
return0;
} #include <bits/stdc++.h>usingnamespacestd;intmain(){string str;while(cin>>str){intcnt=0;intn=str.size();vector<int> dp(n,1);if(n==1) cout<<1<<str[0]<<endl;else{for(inti=1;i<n;i++){if(str[i]==str[i-1]){dp[i]=dp[i-1]+1;}}for(inti=1;i<n;i++){if((dp[i-1]+1)!=dp[i]){cout<<dp[i-1]<<str[i-1];}if(i==n-1) cout<<dp[n-1]<<str[n-1]<<endl;}}}return0;}
#include <string>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
string str;
string res;
cin >> str;
char ch = str[0];
int x = 0;
for (int i = 0; i < str.size(); i++){
if (str[i] == ch){
x++;
}
else{
res.append(to_string(x));
res.push_back(ch);
ch = str[i];
x = 1;
}
if (i == str.size() - 1){
res.append(to_string(x));
res.push_back(ch);
}
}
cout << res << endl;
cin.get();
cin.get();
return 0;
}
/*case通过率只有90%哦*/
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
String str = sc.next();
StringBuilder result=new StringBuilder();
char c=' ';
char[] ch=str.toCharArray();
//count 为重复计数
int count=1;
for(int i=1;i<ch.length;i++){
if(ch[i]==ch[i-1]){
count++;
}else{
result.append(count);
result.append(ch[i-1]);
count=1;
}
if(i==ch.length-1){
result.append(count);
result.append(ch[i]);
}
}
System.out.println(result.toString());
}
}
为什么通过率是90%?print output