#20891: 字串解法


terhead8775 (terhead8775)

學校 : 國立內壢高級中學
編號 : 87826
來源 : [118.168.16.102]
最後登入時間 :
2025-07-23 17:39:32

字串解法
 
#include <iostream>
#include <string>
using namespace std;

 

int main(){
string str;
int a =1;
while(cin >>str){
int len = str.length();
for(int i =0;i<len;i++){
if(str[i]==str[i+1]){
a++;
}
else{
if(a==2)
{
cout << str[i] << str[i];
}
elseif(a!=1)
{
cout << a << str[i];
}
else
{
cout << str[i];
}
a=1;
}
}
cout << endl;
}
return0;
}