前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Codeforces 110B-Lucky String(技能)

Codeforces 110B-Lucky String(技能)

作者头像
全栈程序员站长
发布2022-07-06 10:10:22
2140
发布2022-07-06 10:10:22
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是全栈君。

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 47, 744, 4 are lucky and 5, 17,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:

  • b: 2
  • c: 3, 10
  • d: 4, 8
  • e: 6
  • f: 7
  • z: 1, 5, 9
  • Lists of positions of letters a, g, h, …, y are empty.

This string is lucky as all differences are lucky numbers. For letters z: 5 - 1 = 4, 9 - 5 = 4, for letters c:10 - 3 = 7, for letters d: 8 - 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

代码语言:javascript
复制
5

output

代码语言:javascript
复制
abcda

input

代码语言:javascript
复制
3

output

代码语言:javascript
复制
abc
代码语言:javascript
复制
题意: 要求生成字符串:每一个字母的出现的相邻位置之差为4或7.事实上仅仅须要4个字母就可以 abcdancdabcd....循环输出就可以。
代码语言:javascript
复制
#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.cn/117295.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月8,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档