现在的位置: 首页 > 综合 > 正文

B. Lucky String

2012年04月09日 ⁄ 综合 ⁄ 共 1905字 ⁄ 字号 评论关闭
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 517467 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 c10 - 3 = 7, for
    lettersd8 - 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
    
    Note

    The lexical comparison of strings is performed by the < operator in modern programming languages. String a is lexicographically less than
    string b if exists such i (1 ≤ i ≤ n),
    that ai < bi,
    and for any j (1 ≤ j < iaj = bj.

    解题说明:此题就是要求相同的字母出现的顺序之差为4,7这样的幸运数,简单的做法是每隔4个位置安插一个相同的字母,只用a,b,c,d这四个字母即可。

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include<set>
    #include <algorithm>
    using namespace std;
    
    int main()
    {
    	int n,j,counter=0;
    	scanf("%d",&n);
    	for(j=1;j<=n;j++)
    	{
    		printf("%c",'a'+counter);
    		counter=(counter+1)%4;
    	}
    	return 0;
    }
    	
    

    抱歉!评论已关闭.