hdu 1020 Encoding 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1020
简单模拟
题目大意:把邻近的相同元素收成一格并在其前输出此元素个数(1省略)。
题目分析:无技术含量,模拟水过。
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,flag;
string c;
cin>>n;
while(n--)
{
cin>>c;
while(c.empty()==0)
{
flag=0;
while(c[flag+1]==c[flag])
{
flag++;
}
if(flag)cout<<flag+1<<c[0];
else cout<<c[0];
c.erase(0,flag+1);
}
cout<<endl;
}
return 0;
}
PS:新手期曾做过一次,过得很艰难,这次5min,感慨颇多……

本文介绍了一个简单的编码问题——HDU 1020,该题要求将相邻的相同字符进行压缩,并输出字符及其数量(单个字符不计数)。通过C++代码实现了一种直接的模拟解决方案。
795

被折叠的 条评论
为什么被折叠?



