problem 1320(当时无法AC原因 没有对输入进行限制 如果输入100000(超过10^30)A,则会溢出重回一个比较小的数)

Description
Run-length encoding is a simple compression technique which compresses strings of letters by replacing repeated consecutive letters (called runs) by the number of occurrences of the letter, followed by that letter. For example, AAAABBBCDDE compresses to 4A3BC2DE. The number 1 may be omitted in runs consisting of a single letter, as with letters 'C' and 'E' in the previous example.
Any string consisting of uppercase letters where each letter is optionally preceded by a positive integer is called a properly encoded string. Given a properly encoded string text, you must get the decoded string. If the decoded string would be more than 50 characters long, return "TOO LONG" (without the quotes).


Input
There are serveal test case , each case contain a string(the length no more than 50).


Output
For each case , output the decoded string or "TOO LONG"


Sample Input

4A3BC2DE
21Z13S9A8M


Sample Output

AAAABBBCDDE
TOO LONG


Hint
The decoded string would be more than 10^30 characters long, which is more than 50.

Source
Buptacm

 

自己的:

 

#include<iostream>
#include<string.h>
using namespace std;
int main()

char a[50];
int b[50];
for(int i=0;i<50;i++)
b[i]=0;
while(cin>>a)
{
int i=0,j=0,k=0,m=0;
  while(a[i]!='/0')
{
while((a[i]<='9')&&(a[i]>='0'))
{
   
j=j*10+(int(a[i])-48); 
i++;
if(j>50)     //对J限制 超过50直接判错!!!!!
{
  cout<<"TOO LONG";
  goto qq;
}
}
while((a[i]<='Z'&&a[i]>='A'))
{
if(j==0)
{b[k]=1;}
else
{b[k]=j;}

j=0;
i++;
m=m+b[k];
k++;
}
}
  if(a[i]=='/0')
{
if(m>50)
cout<<"TOO LONG";
else
{
i=0,j=0;
while(a[i]!='/0')
{
while((a[i]<='9')&&(a[i]>='0'))
{
   
j=j*10+(int(a[i])-48); 
i++;
 
}
while((a[i]<='Z'&&a[i]>='A'))
{
cout<<a[i];
while(j>1)
{
cout<<a[i];
j--;
}
j=0;
i++;
}
}
}
}
qq:
  cout<<endl;
}

return 0;
 
}

 

学到的:字符串中的数字转字符 强制转换INT后减去0的ASCII码48 int('9')-48;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值