首页 > ACM题库 > HDU-杭电 > hdu 3583 CodeMaker待解决[解题报告]C++
2014
11-27

hdu 3583 CodeMaker待解决[解题报告]C++

CodeMaker

问题描述 :

Dreamwind is doing C++ homework……
“Write a program, enter 3 different integers a,b,c, output them in increasing order using their variable names.”
This is Dreamwind’s answer:
#include <stdio.h>

int a,b,c;
bool ok;

int main()
{
    printf("Please enter 3 different integers:\n");
    do
    {
      scanf("%d%d%d",&a,&b,&c);
      ok=1;
      if (a==b || a==c || b==c)
        ok=0;
    }while (ok);
    if (a<b)
      if (b<c)
        printf("a<b<c\n");
      else
        if (a<c)
          printf("a<c<b\n");
        else
          printf("c<a<b\n");
    else
      if (a<c)
        printf("b<a<c\n");
      else
        if (b<c)
          printf("b<c<a\n");
        else
          printf("c<b<a\n");
    return 0;
}
Obviously, this program is very complex, but Dreamwind is satisfied with this. He prepares to solve similar question by using the same format. However, when the nubmer of integers if very large, the length of code by this format will be very long, so Dreamwind gives this code to you, hoping you can write a program which can create the code of some questions like “Enter n different integers a,b,c,…, output them in increasing order using their variable names.” automatically.
We can see that in Dreamwind’s format, the integers’ variable name will be a,b,c,…, and when judge whether the integers are different, the “if” will follow many sentence like (a==b) in some order. When compare the integers, he uses the least “if” so that every “if” and “else” is perfectly used. For each comparison, a and b will always be used first, and then c, and then d (if n is larger, see the Sample Output). Dreamwind never use “>” in this program, and in every “<” and “==” in the “if” sentence, the varible name on the left will always smaller than the one on the right.

输入:

There are some test cases. For each test case there is only one line with a integer n (2<=n<=8), the number of integers. There is one 0 in the end of the case.

输出:

There are some test cases. For each test case there is only one line with a integer n (2<=n<=8), the number of integers. There is one 0 in the end of the case.

样例输入:

4
0

样例输出:

#include <stdio.h>

int a,b,c,d;
bool ok;

int main()
{
	printf("Please enter 4 different integers:\n");
	do
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ok=1;
		if (a==b || a==c || a==d || b==c || b==d || c==d)
			ok=0;
	}while (ok);
	if (a<b)
		if (b<c)
			if (c<d)
				printf("a<b<c<d\n");
			else
				if (b<d)
					printf("a<b<d<c\n");
				else
					if (a<d)
						printf("a<d<b<c\n");
					else
						printf("d<a<b<c\n");
		else
			if (a<c)
				if (b<d)
					printf("a<c<b<d\n");
				else
					if (c<d)
						printf("a<c<d<b\n");
					else
						if (a<d)
							printf("a<d<c<b\n");
						else
							printf("d<a<c<b\n");
			else
				if (b<d)
					printf("c<a<b<d\n");
				else
					if (a<d)
						printf("c<a<d<b\n");
					else
						if (c<d)
							printf("c<d<a<b\n");
						else
							printf("d<c<a<b\n");
	else
		if (a<c)
			if (c<d)
				printf("b<a<c<d\n");
			else
				if (a<d)
					printf("b<a<d<c\n");
				else
					if (b<d)
						printf("b<d<a<c\n");
					else
						printf("d<b<a<c\n");
		else
			if (b<c)
				if (a<d)
					printf("b<c<a<d\n");
				else
					if (c<d)
						printf("b<c<d<a\n");
					else
						if (b<d)
							printf("b<d<c<a\n");
						else
							printf("d<b<c<a\n");
			else
				if (a<d)
					printf("c<b<a<d\n");
				else
					if (b<d)
						printf("c<b<d<a\n");
					else
						if (c<d)
							printf("c<d<b<a\n");
						else
							printf("d<c<b<a\n");
	return 0;
}


  1. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.

  2. for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
    dp = dp [j-1] + 1;
    if(s1.charAt(i-1) == s3.charAt(i+j-1))
    dp = dp[i-1] + 1;
    if(s2.charAt(j-1) == s3.charAt(i+j-1))
    dp = Math.max(dp [j - 1] + 1, dp );
    }
    }
    这里的代码似乎有点问题? dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false

  3. #include <cstdio>

    int main() {
    //answer must be odd
    int n, u, d;
    while(scanf("%d%d%d",&n,&u,&d)==3 && n>0) {
    if(n<=u) { puts("1"); continue; }
    n-=u; u-=d; n+=u-1; n/=u;
    n<<=1, ++n;
    printf("%dn",n);
    }
    return 0;
    }

  4. Good task for the group. Hold it up for every yeara??s winner. This is a excellent oppotunity for a lot more enhancement. Indeed, obtaining far better and much better is constantly the crucial. Just like my pal suggests on the truth about ab muscles, he just keeps obtaining much better.