GDUT_排位赛题解报告_第4场_C. Defining Labels

本文探讨了在Microsoft Excel中,如何将数字转换为特定基数的列标签,使用了一种新颖的方法来代替传统的字母标签,涉及到数学转换和编程实现。

题目:

Microsoft Excel is a spreadsheet developed by Microsoft. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications. It has been a very widely applied spreadsheet for many different operating systems, especially since version 5 in 1993, and it has replaced Lotus 1-2-3 as the industry standard for spreadsheets.

In Excel, the labelling for columns uses upper case letters instead of numbers to distinguish it from the labelling for rows. The first column in Excel is labelled A, the second is labelled B and so on. And after column Z, the next columns are labelled AA,AB,⋯,ZZ,AAA,⋯.

In this problem, we’ll define a new labelling scheme. Let’s use numerical digits instead of letters, and only a subset of the digits. Let’s define base k (2≤k≤10) labelling as using only digits from 10−k to 9 in the labels. For example, the labels in base 10 in ascending order are 0,1,⋯,9,00,01,⋯, and in base 7 they are 3,4,⋯,9,33,34,⋯.

Now, given k and X, your task is to find the X-th label in base k.

Input
The input contains multiple cases. The first line of the input contains a single integer T (1≤T≤105), the number of cases.

For each case, the first line of the input contains a single integer k (2≤k≤10), the base of the labelling scheme. The second line contains a single integer X (1≤X≤109), the number of the label you need to find.

Output
For each case, print a single string in a single line, the X-th label.

Example
inputCopy
2
10
10
5
10
outputCopy
9
59

这个题意简单,就是求26进制的第几个数,但是要处理一下,也算是数学题目:

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <climits>
#include <queue>
#include <stack>
#include <map>
//鬼畜头文件
using namespace std;
const int INF = 0x3f3f3f3f;
//1.06e9大小
const int mod = 1e9+7;
typedef unsigned long long ULL;
typedef long long LL;
//鬼畜define
int t;
int k,x;
int all[35];
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&k,&x);
		if(x%k!=0)
		{
			all[0]=x%k+9-k;
		}
		else
		{
			all[0]=9;
			--x;
		}
		x/=k;
		int bit=1;
		for(;x!=0;++bit)
		{
			if(x%k==0)
			{
				all[bit]=9;
				--x;
			}
			else
			{
				all[bit]=x%k+9-k;
			}
			x/=k;
		}
		for(int time=bit-1;time>=0;--time)printf("%d",all[time]);
		printf("\n");
	}
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值