sicily 1753

来源:互联网 发布:北航矩阵论 编辑:程序博客网 时间:2024/05/08 17:38
#include "iostream"#include "cctype"#include "string"#include "sstream"using namespace std;int main(){string str;while (cin >> str && str != "XXX"){int size;size = str.size();for (int i = 0; i < size; i++){if (isdigit(str[i])){int count = 0;//计算数字的个数int tag = i;//状态位的保存int tag1 = i;//状态位的保存int Num = 0;//保存由字符串转换过来的数字,即是前一个字母出现的个数while (isdigit(str[tag1]))//计算字符串中连续有多少个数字的出现的个数{count++;tag1++;if (tag1 >= str.size())  break;}string temp = "";for (int j = 1; j <= count; j++, tag++)//下面的步骤是讲字符串中的数字转换为int{temp += str[tag];}stringstream s;s << temp;s >> Num;for (int j = 1; j < Num; j++)//输出字母cout << str[i-1];i = i + temp.size() - 1;//得到获取了字符串中数字之后的游标位置,继续下个字母的检验}elsecout << str[i];}cout << endl;}}

 
原创粉丝点击