黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character

链接:https://ac.nowcoder.com/acm/contest/877/A
来源:牛客网
 

题目描述

黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character今天在给黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character

的同学们上程序算法课的时候出了一道找规律的题目,题目表述如下

假设:

黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character

现在黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character要求上课的同学们把所有的串依次连接起来,于是得到:

黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character

那么你能告诉黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character串中的第黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character个字母是多少吗?
 


 

 

输入描述:

 

输入首先是一个数字黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character,代表有黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character次询问黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character

接下来的黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character行每行有一个整数黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character

 

输出描述:

 

对于每次询问,输出黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character串中第黑龙江大学程序设计竞赛(重现赛)——A题Find the Nth Character个位置对应的字母。

示例1

输入

复制

6
1
2
3
4
5
10

输出

复制

a
a
b
a
b
d

这道题用到了一点小技巧,总体来说不难

源代码:

#include <stdio.h>
#include <string.h>

int main()
{
	int t=0,sum=0,tt=0,n,x;//sum记录在str中字符数量,tt记录str0中字符数量 
	char str0[10001]; 
	char str[10001];
	
	while(sum<=10000)//这一步是求出长度在10000题目要求的字符串 
	{
		str0[tt++]='a'+t%26;
		t++;				 
		str0[tt]='\0';
		strcat(str,str0);
		sum+=(tt);
	}
	
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&x);
		printf("%c\n",str[x-1]);
	}
	return 0;
} 

 

相关文章: