【2012年腾讯俱乐部ACM赛新手组1000】我水平弱爆了—Love Message

做了三个题,然后拖走上课去了……我的Q币大哭 其实仔细看看自己水平之内的话可以5AC的。

Description

      Jiangshan and Zhao Yiran is a sweetheart lover in different class. So, Jiangshan developed a application to send message to Zhao Yiran through wireless. However, so unfortunately, their teachers are so great that all they send will be received by their teachers too. In order to keep their message secrecy, they have to encrypt the message.

      When a char X appear n times, Jiangshan will show it as Xn, for example bb->b2. In order to get the love message, Zhao Yiran have to deciphering the message with mind acts upon mind. Could you help they to deciphering.
Input

      A string S, indicates the message Zhao Yiran get, all the char is lower case. There may be several test cases in the input file and end when S equal to XXX.

Output
Sample Input
 Copy sample input to clipboard
a3
go12gle
XXX
Sample Output
aaa
goooooooooooogle

现场居然没AC,ORZ:

#include <iostream>
#include <string>
#include <ctype.h>
#include <stdlib.h>

using namespace std;

int cun(int n)
{      
    if(n<10)
      return 1;
   return cun(n%10)+1;
}

int main()
{
	string inner;
	while(cin>>inner && inner!="XXX")
	{
		int i;
		for(i=0;i<inner.size();i++)
		{
		
			
			if(islower(inner[i]))
				cout<<inner[i];
			else
			{
				string loop;
				char p;
				p=inner[i-1];
				

				for(int j=i;j<inner.size();j++)
				{
					if(isdigit(inner[j]))
					{
						loop+=inner[j];//如果用loop[j-i]的话会出问题,典例若:a10b5.B的数量会异常增高
					    				//这个是STRING的缓冲区漏洞 
					}
					else
						break;
				}
				int dw=0;
				dw=atoi(loop.c_str());
				
				for(int t=0;t<dw-1;t++)
				{
					cout<<p;
				}	
				i=(i+cun(dw)-1);	
			}
						

		}
			cout<<endl;
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值