一道偶尔想起来的笔试题

有一个题目,有一天突然看到,题目大概的意思是,输入字符串AAABBV
输出:A3B2V

#include <iostream>
#include <string>
using namespace std;
int main(void)
{
string str;
cin>>str;

int len = str.length();
int count = 1;
int i=0;
int j=0;
for(i =1,j =i-1;i<len;++i,++j)
{
	
	 if(str[j] != str[i])
	{
		cout<<str[j]<<count;
		count =1;
	} else {
	count++;
	
	}

	 if(i==len-1)
	{
		if(str[i] == str[j])
		{cout<<str[j]<<count;
		}else
		{
			cout<<str[i]<<1;
		}
	}
}
system("pause");
return 0;
}
原文地址:https://www.cnblogs.com/zhuyaguang/p/5671429.html