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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • java calendar 设置小时_Java Calendar类的时间操作[通俗易懂]

    java calendar 设置小时_Java Calendar类的时间操作[通俗易懂]JavaCalendar类时间操作,这也许是创建日历和管理最简单的一个方案,示范代码很简单,演示了获取时间,日期时间的累加和累减,以及比较。注意事项:Calendar的month从0开始,也就是全年12个月由0~11进行表示。而Calendar.DAY_OF_WEEK定义和值如下:Calendar.SUNDAY=1Calendar.MONDAY=2Calend…

    2022年4月30日
    210
  • UML图:类图 –详细介绍

    UML图:类图 –详细介绍类图的概念描述类、接口及它们之间关系的图,显示系统中各个类的静态结构类图的元素类面向对象系统组织结构的核心对一组具有相同属性、操作、关系和语义的对象的抽象包括名称部分(Name)、属性部分(Attribute)和操作部分(Operation)类的组成名称属性操作名称:应该是一个名词,分为简单名称和路径名称,每个单词首字母大写属性:描述了类在软件系统中代表的事物(即对象)所具备的特性,类可以有任意数目的属性,也可以没有属性在UML中,类属性的语法为属性的可见性

    2022年7月12日
    21
  • 分布式熔断机制_服务器熔断是什么意思啊

    分布式熔断机制_服务器熔断是什么意思啊#服务熔断-“熔断器”本身是一种开关装置,当某个服务单元发生故障之后,通过断路器(hystrix)的故障监控,某个异常条件被触发,直接熔断整个服务。向调用方法返回一个符合预期的、可处理的备选响应(FallBack),而不是长时间的等待或者抛出调用方法无法处理的异常,就保证了服务调用方的线程不会被长时间占用,避免故障在分布式系统中蔓延,乃至雪崩。如果目标服务情况好转则恢复调用。服务熔断是解决服务雪崩的重要手段。#服务熔断图示…

    2022年8月31日
    2
  • adb命令fastboot线刷_fastboot线刷

    adb命令fastboot线刷_fastboot线刷app稳定性测试工具使用方法

    2025年9月4日
    2
  • 死磕Lambda表达式(六):Consumer、Predicate、Function复合

    死磕Lambda表达式(六):Consumer、Predicate、Function复合JDK不仅提供的这些函数式接口,其中一些接口还为我们提供了实用的默认方法,这次我们来介绍一下Consumer、Predicate、Function复合。

    2025年7月5日
    7
  • 杭电 1142 十字链表存储

    杭电 1142 十字链表存储  本来是想用二维数组实现的,但是想了一下发现,如果数据是稀疏矩阵的话,用二维数组存就会造成很多的空间浪费,而且遍历的时候也很浪费时间。学数据结构的时候书上教我们使用十字链表来存储稀疏矩阵,于是就想着用十字链表来实现。然后我发现我忘了十字链表的代码实现了…默默地去翻书,捣置了好久,终于写好了,乐滋滋的去oj提交代码,结果时间超限……  哎~把代码贴上来,就当加深一下十字链表的记忆吧~~#in…

    2022年6月18日
    24

发表回复

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

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