B. Decode String Codeforces Round #820 (Div. 3)

本文介绍了一种字符串解码算法,该算法将特定规则编码的字符串还原为其原始形式。编码规则涉及字母在字母表中的位置,并根据该位置是否为个位数来决定编码方式。文章详细解释了逆向模拟的解码过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

 题意:一个字符串t的每一个字母进行一次编码,规则为

定义字母数位这个字符在字母表中的顺序。

如果字母数是个位数(小于10),就直接写出来;

如果字母数字是两位数(大于或等于10),则将其写出来并在后面加上数字0。

现在给你转换后的字符串,让你求t。

思路:直接倒着模拟就可以了,记得为0 的时候处理一下下标。

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
char s[N];
char cnt[N];


int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		sc_int(n);
		cin>>s+1;
		int top=0;
		for(int i =n;i>=1;i--)
		{
			if(s[i]!='0')
			cnt[++top]=s[i]-'0'+'a'-1;
			else{
				i-=1;
				cnt[++top]=(s[i]-'0')+(s[i-1]-'0')*10+'a'-1;
				i-=1;
			}
				// cout<<cnt[top]<<" "<<i<<endl;			
		}
		while(top)
		cout<<cnt[top--];
		cout<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值