[Arrays]Decode the string

Description

XiaoMing is a student of BigMount Middle School. One day, he wants to send a very very long message to his friend, Bob. His SIM card is China Mobile. As we all know, the fee of cellphone data plan is very expensive. To save money, he thinks of an idea to shorten the message. He uses a number to indicate how many times of the letter before appears.

For example, he replaces "aaa" with "a3". (3 indicates there are three 'a')

After sending the message, he tells Bob the rule. But Bob is a little clumsy. He doesn't know how to decode the message.

Now please help Bob to decode the string he received to get the original message.

input

a string which Bob received, including character and number(no space). The number is in [1, 1000]. And the length of the string is less than 100.

output

the original string

Note: The number N in the string may be too big, which makes the output too long. So before output, if N > 7, you need to let N = N % 7 + 1

sample input

a3.3kil2me.h3!23

sample output

aaa...killme.hhh!!!

(23 % 7 + 1 = 3, so we just output three '!')
#include<stdio.h> 
int find(char g[],int n);
int find(char g[], int n)
{
	if (g[n] >= 48 && g[n] <= 57)
		return 1;
	else
	    return 0;
}

int number(char g[], int n);
int number(char g[], int n)
{
	int num = 0;
	while (g[n] >= 48 && g[n] <= 57)
	{
		num = num * 10 + (int)g[n] - 48; n++;
	}
	if (num > 7)
		num = num % 7 + 1;
	return num;
}
int longer(char g[],int n);
int longer(char g[], int n)
{
	while (g[n] >= 48 && g[n] <= 57)
		n++;
		return n;
}


int main()
{
	int n, i,a;
	char g[100];
	scanf("%s", g);
	for (n = 0; g[n] != '\0'; n++)
	{
		if (find(g, n))
		{
			a = number(g, n);
			for (i = 1; i < a; i++)
				printf("%c", g[n - 1]);
			n = longer(g, n) - 1;
		}
		else
			printf("%c", g[n]);
	}
	printf("\n");
	return 0;
}

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值