1078 字符串压缩与解压 c++
·
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
char c;
cin>>c;
char huan;
huan=cin.get();
char x[1001];
char s[1001];
int y[1001]={0};
if(c=='C'){
x[0]=cin.get();
s[0]=x[0];
int i;
for(i=1;;i++){
x[i]=cin.get();
if(x[i]=='\n'){
break;
}
if(x[i]==x[i-1]){
y[i-1]++;
i--;
}else{
s[i]=x[i];
}
}
for(int j=0;j<i;j++){
if(y[j]==0){
cout<<s[j];
}else{
cout<<y[j]+1<<s[j];
}
}
}else{
int i=0;
while(1){
x[i]=cin.get();
if(x[i]=='\n'){
break;
}
if(x[i]>='0'&&x[i]<='9'){
y[i]=y[i]*10+x[i]-'0';
i--;
}else{
s[i]=x[i];
}
i++;
}
for(int j=0;j<i;j++){
if(y[j]==0){
cout<<x[j];
}else{
for(int p=0;p<y[j];p++){
cout<<s[j];
}
}
}
}
}
更多推荐
所有评论(0)