GDUT_排位賽題解報告_第4場_C. Defining Labels

題目:

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");
	}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章