zoukankan      html  css  js  c++  java
  • Codeforces 110B-Lucky String(技能)

    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]='';
    		puts(s);
    	}
    	return 0;
    }


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    201202
    Android牟利之道(一)界面嵌入有米广告
    SoketException log
    ERROR: 9patch image about.9.png malformed.
    Conversion to Dalvik format failed with error 1
    absolute绝对定位(相对于整个html流)以及不为人知的(fixed)绝对定位(fixed相对于浏览器窗口=不动的div)
    about getElementsByTagName()的那点事
    js 不用onload的loding
    absolute fixed效果 复制网页打开就是代码 http://www.cnblogs.com/0banana0/archive/2011/05/25/2056643.html
    关于datetime的那点事
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4723301.html
Copyright © 2011-2022 走看看