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)
上一篇 2022年1月8日 上午6:00
下一篇 2022年1月8日 上午6:00


相关推荐

  • Python数据类型有哪些,哪些是可变类型,哪些是不可变类型?

    Python数据类型有哪些,哪些是可变类型,哪些是不可变类型?Python数据类型有哪些,哪些是可变类型,哪些是不可变类型?类型:整数int字符串str浮点数float布尔型bool列表list字典dict集合set元组tuple可变类型:就是这个数据类型的值在不改变这一块内存空间,而去改变这个数据类型的值。1.列表2.字典3.集合不可变类型:当改变值得时候,会申请一块新的内存空间,不再是原来的那一块内存空间了。整数字符串浮点数布尔型元组…

    2022年6月10日
    35
  • 《物流与供应链管理》课程论文

    《物流与供应链管理》课程论文《物流与供应链管理》课程论文题目:基于重心法的物流配送中心选址研究学生姓名贾树丙学号110104200208指导教师于德建二级学院信息学院专业名称计算机科学与技术班级11计算机2201

    2022年8月4日
    8
  • java代码生成器,springboot代码生成器—增加更新,查询功能(持续更新)

    java代码生成器,springboot代码生成器—增加更新,查询功能(持续更新)时隔一周多,今天终于抽出时间来更新一波代码生成器,最近公司让我研究rpa,弄得焦头烂额的,话不多说,进入正题。之前有朋友让我讲一下代码生成器的原理,这篇博客就大体描述一下,以后慢慢细致讲解。双击codeMan.exe,众所周知,java做成exe程序很麻烦,在这里我是利用了.net的ikvm插件把jar包直接编译成了exe程序,这个启动界面会连接我的服务器,去检查版本更新,如果有更新就会在…

    2022年6月5日
    35
  • Win10 pycharm anaconda 配置多环境走一波!

    Win10 pycharm anaconda 配置多环境走一波!没想到 第一篇博客是关于 win10pycharm 如何配置 conda 多环境的 Win10pycharm 配置多环境走一波 首先在进行 pycharm 配置前 确保你有打开 pycharm 的管理员权限 如果你是在一台服务器上和大家共同使用 这里就必须要管理员权限 右键管理员身份运行 pycharm 如果是自己的电脑就算了 如果你在创建过程中遇到了 Permissi

    2026年3月27日
    3
  • Java分布式事务

    Java分布式事务分布式事务介绍事务拥有以下四个特性,习惯上被称为ACID特性:

    2022年6月14日
    34
  • J2ME开发资料[通俗易懂]

    J2ME开发资料[通俗易懂]分享一个实用的网络连接类:http://www.cnblogs.com/psunny/archive/2009/12/06/1617875.html一些知名的J2me优秀开源UI项目: http://www.cnblogs.com/psunny/archive/2009/09/23/1572740.html最佳的线程联网类:http://www.cnblogs.com/psunny/arch

    2022年7月11日
    19

发表回复

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

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