火柴棍--解题报告

           

如下图,可以用火柴棍来表示数字:

 

现在,你手里有一定数量的火柴棍,请给出你能用这些火柴棍所表示的数字的范围(要求使用全部的火柴棍,并且数字不能用0开头)

输入的第一个整数T表示有多少组测试数据(1≤T≤100)。每组测试数据为一行,只有一个整数,即代表了你手中的火柴棍的数量n(2≤n≤100)。

为每组测试数据输出一行,由2个整数组成,分别对应所表示的最小和最大的整数,中间使用一个空格隔开。

#include<stdio.h>
int main()
{
 
    int a,b,c,j,e,i,t,m,k;
    scanf("%d",&a);
    for(b=1; b<=a; b++)
    {
        scanf("%d",&c);
        if(c<=7)
        {
            if(c==2)
                printf("1 ");
            if(c==3)
                printf("7 ");
            if(c==4)
                printf("4 ");
            if(c==5)
                printf("2 ");
            if(c==6)
                printf("6 ");
            if(c==7)
                printf("8 ");
        }
        else if((c>7)&&(c<=14))
        {
            if(c%7==0)
                printf("88 ");
            if(c%7==1)
                printf("10 ");
            if(c%7==2)
                printf("18 ");
            if(c%7==3)
                printf("22 ");
            if(c%7==4)
                printf("20 ");
            if(c%7==5)
                printf("28 ");
            if(c%7==6)
                printf("68 ");
        }
 
        else if((c>14)&&(c<=21))
 
        {if(c%7==0)
                printf("888 ");
            if(c%7==1)
                printf("108 ");
            if(c%7==2)
                printf("188 ");
            if(c%7==3)
                printf("200 ");
            if(c%7==4)
                printf("208 ");
            if(c%7==5)
                printf("288 ");
            if(c%7==6)
                printf("688 ");}
 
        else if(c>21)
            {if(c%7==0)
                printf("88");
            if(c%7==1)
                printf("108");
            if(c%7==2)
                printf("188");
            if(c%7==3)
                printf("200");
            if(c%7==4)
                printf("208");
            if(c%7==5)
                printf("288");
            if(c%7==6)
                printf("688");
 
               t=c/7;
                m=t-2;
               if(m>=1)
               {
 
                for(k=1; k<m; k++)
                {
                    printf("8");
                }
                printf("8 ");}
 
        }
 
 
        i=c/2;
        if(c%2==0)
        {
            for(j=1; j<=i-1; j++)
            {
                printf("1");
            }
            printf("1\n");
        }
      if(c%2==1)
        {
            if(c==3)
            {
                printf("7\n");
            }
 
            else
            {
                printf("7");
                for(e=1; e<=i-2; e++)
                {
                    printf("1");
                }
                printf("1\n");
            }
        }
    }
    return 0;
}解题思路----我是找规律解得--1,就是求最大数时,先让它位数最多,所以除二,2,求最小数时时让它位数最少,所以除7,然后调整位置,3,注意细节
ac了后看看别人的代码,懂了。自己代码太不简洁。 
 
 
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页