Codeforces 110B-Lucky String(技能)

Codeforces 110B-Lucky String(技能)

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

B. Lucky String
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 477444 are lucky and 517,467 are not.

Petya recently learned to determine whether a string of lowercase Latin letters is lucky. For each individual letter all its positions in the string are written out in the increasing order. This results in 26 lists of numbers; some of them can be empty. A string is considered lucky if and only if in each list the absolute difference of any two adjacent numbers is a lucky number.

For example, let’s consider string “zbcdzefdzc“. The lists of positions of equal letters are:

  • b2
  • c3, 10
  • d4, 8
  • e6
  • f7
  • z1, 5, 9
  • Lists of positions of letters agh, …, y are empty.

This string is lucky as all differences are lucky numbers. For letters z5 - 1 = 49 - 5 = 4, for letters c:10 - 3 = 7, for letters d8 - 4 = 4.

Note that if some letter occurs only once in a string, it doesn’t influence the string’s luckiness after building the lists of positions of equal letters. The string where all the letters are distinct is considered lucky.

Find the lexicographically minimal lucky string whose length equals n.

Input

The single line contains a positive integer n (1 ≤ n ≤ 105) — the length of the sought string.

Output

Print on the single line the lexicographically minimal lucky string whose length equals n.

Sample test(s)
input
5

output
abcda

input
3

output
abc
题意: 要求生成字符串:每一个字母的出现的相邻位置之差为4或7.事实上仅仅须要4个字母就可以 abcdancdabcd....循环输出就可以。

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
#define LL long long
char s[1000000];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		{

			if((i+1)%4!=0)
				s[i]='a'+(i+1)%4-1;
			else
				s[i]='d';
		}
		s[n]='\0';
		puts(s);
	}
	return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117295.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • TLSF内存分配器记录[通俗易懂]

    TLSF内存分配器记录[通俗易懂]论文:《TLSF:aNewDynamicMemoryAllocatorforReal-TimeSystems》这也是Unity底层使用的内存分配器。我直接从论文中间部分开始看。firstlevel存的是每个内存分配大小,从2的四次方到2的31次方。而对应每个大小,又指向一个二级列表,里面被分成4级,每一级的范围认为是同一类。1表示空闲,所以只有2的六次方和2的15次方块是空闲的。再看它指向的二级列表。只有2的六次方+16到2的6次方+32的这个.

    2022年6月26日
    44
  • AWE2017今日召开 智能家居发展势头强劲

    AWE2017今日召开 智能家居发展势头强劲

    2022年3月4日
    36
  • Java HttpURLConnection setRequestProperty(“content-length“, “0“)不起作用

    Java HttpURLConnection setRequestProperty(“content-length“, “0“)不起作用Post验证Url合法的时候,今天突然遇到一个用IIS的客户,结果返回411的statuscode.搜索原因是请求头中没有设置Content-Lenght。网上的教程说用setRequestProperty(“content-length”,“0”)设置一下,结果我测试还是返回411.调试发现:为了安全,这些头默认是不允许指自定义的。可以通过下面方法打开,尽量将下面的语句放到main中:System.setProperty(“sun.net.http.allowRestrictedHead

    2022年9月3日
    6
  • 孙鑫java视频教程笔记[通俗易懂]

    孙鑫java视频教程笔记[通俗易懂](3)为了防止类或函数被覆盖,可以用final声明。private和static默认为final(6)接口中的数据成员默认为publicstaticfinal。(7)java不允许类的多继承,允许类的单继承和接口的多继承。(9)内部类通过this机制可以随意访问外部类的成员。(10)java.lang包被隐形自动导入,不需要import。(12)string是唯一被重载的对

    2022年5月17日
    47
  • Gloand 2021 激活码【2021.10最新】

    (Gloand 2021 激活码)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年3月28日
    40
  • 深度剖析LinkedHashSet「建议收藏」

    深度剖析LinkedHashSet「建议收藏」HashMap是一个利用数组存储key-value键值对的一个数据结构,为了有序的要求,然后我们引入了LinkedHashMap来满足我们对顺序的要求,再到后面我们学习了HashSet这种数据结构,利用的是HashMap的Key的唯一性来实现HashSet的去重的目的LinkedHashSet也HashSet一样也在内部使用了HashMap,因为LinkedHashSet要维持元素之间的顺序,所以它使用的实HashMap的有序版本,也就是LinkedHashMap

    2022年10月12日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号