字符串转换:原字符串字符+该字符出现的次数

例如:

输入:1233422222 输出:1121324125

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int main(int arc, char** argv)
{
	char *str="1233422222";
	string nstr;

	int i=0;
	while(1)
	{
		int cnt=1;
		while(str[i+1]==str[i])
		{
			i++;
			cnt++;
		}
		nstr+=str[i];
		nstr+=cnt+'0';
		//cout<<str[i]<<cnt;
		i++;
		if(str[i+1]=='\0')
		{
			break;
		}
	}

	cout<<nstr<<endl;
	system("pause");
	return 0;
}


你可能感兴趣的:(字符串转换,原字符串字符+该字符出现的次数)