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


相关推荐

  • Linux学习——yum学习和光盘yum源搭建「建议收藏」

    yum安装和光盘yum源搭建在rmp安装的时代,rpm包依赖让安装人员头大,而且头疼,有了yum后整个的安装更加简单和方便。

    2022年2月26日
    60
  • 网络协议的三要素是什么?各有什么含义?_网络协议三要素中语法规定了

    网络协议的三要素是什么?各有什么含义?_网络协议三要素中语法规定了网络协议的三要素是什么?1、语法语法用来规定信息格式。数据及控制信息的格式、编码及信号电平等。2、语义语义用来说明通信双方应当怎么做。用于协调与差错处理的控制信息。3、定时定时(时序)定义

    2022年8月4日
    4
  • AIC和BIC准则详解

    AIC和BIC准则详解很多参数估计问题均采用似然函数作为目标函数,当训练数据足够多时,可以不断提高模型精度,但是以提高模型复杂度为代价,同时带来一个机器学习中非常普遍的问题——过拟合。所以,模型选择问题在模型复杂度与模型对数据集描述能力(即似然函数)之间寻求最佳平衡。人们提出许多信息准则,通过加入模型复杂度的惩罚项来避免过拟合问题,此处我们介绍一下常用的两个模型选择方法:1.赤池信息准则(AkaikeInformationCriterion,AIC)AIC是衡量统计模型拟合优良性的一种标准,由日本统计学家赤池弘次在

    2022年5月23日
    80
  • 股票软件开发

    股票软件开发求助编辑百科名片股票软件开发顾名思义就是股票软件开发公司为公司或个人开发制作自已个性化的股票分析软件,从此彻底告别依赖别人的技术平台支持,从股票软件名称,公司LOGO,启动界面,系统功能,特色指标、特色选股、软件注册后台,信息发布平台,机构数据,主力行情,大盘分析,个股分析,资金分析,热点分析等等一系列功能上实行自已品牌化管理运行。目录

    2022年4月10日
    91
  • Kafka动态调整topic分区partition

    Kafka动态调整topic分区partition我们在使用kafka时,初期创建时所指定topic属性需要修改,如何动态修改kafka属性?kafka提供了命令行工具—kafka-topics.sh.kafka-topics.sh工具介绍kafka-topics.sh工具也是我们用来创建topic、查看topic详情的工具。直接运行kafka-topics.sh可以产出它是用来创建、删除、查看以及更新topicroot@ubuntu……

    2022年10月17日
    2
  • 操作系统概念第五章部分作业题答案

    操作系统概念第五章部分作业题答案题目一:为什么对调度程序而言,区分CPU约束性进程和I/O约束性进程很重要解答:绝大多数进程可分为I/O主(放入I/O队列)或CPU主(放入就绪队列),I/O主的计算时间>CPU主。因此长期调度程序应选择一个合理的包含I/O主和CPU主的组合进程。在运行I/O操作前,I/0限制的程序只运行很少数量的计算机操作。而CPU约束程序一般来使用很多的CPU。另一方面,CPU约束程序会利用整个时间片,…

    2022年7月14日
    11

发表回复

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

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