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


相关推荐

  • php 工厂方法模式

    php 工厂方法模式

    2022年7月25日
    9
  • dnslog

    0x00前言我们在盲注的时候,会非常的繁杂,发起大量的请求容易被禁ip。爆数据的时候也比较慢,所以我们需要用到dnslog盲注。0x01dnslog盲注dnslog盲注条件:dnslog&#160

    2021年12月11日
    89
  • Socket粘包问题「建议收藏」

    Socket粘包问题「建议收藏」什么时候要考虑粘包问题1.:如果利用tcp每次发送数据,就与对方建立连接,然后双方发送完一段数据后,就关闭连接,这样就不会出现粘包问题(因为只有一种包结构,类似于http协议)。关闭连接主要要双方都发送close连接(参考tcp关闭协议)。如:A需要发送一段字符串给B,那么A与B建立连接,然后发送双方都默认好的协议字符如”hellogivemesthabouryourself”,然后

    2022年8月11日
    7
  • STM32F103+RFID-RC522模块 实现简单读卡写卡demo「建议收藏」

    目录前言代码下载:功能介绍:接线STM32STM32F1开发指南(精英版)-库函数版本_V1.2STM32中文参考手册RFID-RC522RFID射频模块电路原理图使用图+效果图一、先用手机软件NFCWriter读取空卡看看内容1、打开软件和NFC(ps:我的手机是小米10)2、将空卡贴于手机背部,弹出提示发现新卡,点击“好的”3、上面的新卡片左滑到新卡片1,单击这个卡片4、进入卡片信息详细页面钥匙扣卡M1空白卡二、编译、烧写程序三、将钥匙扣卡发在模块上,打开串口,开始测试核心代码main.crc522.

    2022年4月7日
    62
  • 一个服务器上运行多个tomcat,显示总启动某一个特定tomcat

    一个服务器上运行多个tomcat,显示总启动某一个特定tomcat

    2021年7月17日
    71
  • Adroid 收集

    Adroid 收集用两张图告诉你,为什么你的App会卡顿?-Android-掘金Cover有什么料?从这篇文章中你能获得这些料:知道setContentView()之后发生了什么?…Android获取View宽高的常用正确方式,避免为零-掘金相信有很多朋友都有过在Activity中通过getWidth()之类的方法获取View的宽高值,可能在onCreat…

    2022年5月25日
    33

发表回复

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

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