zoukankan      html  css  js  c++  java
  • SDUST T1584 G's present

    G's present

    Time Limit: 1 Sec  Memory Limit: 128 MB

    Description

       In the ACM International Collegiate Programming Contest, each team consist of three students. And the teams are given 5 hours to solve between 8 and 12 programming problems. 
       In SDUST, there is programming contest, too. Each team consist of 3 students. The teams are given 5 hours to solve 11 programming problems. Each team can use only one computer, and they can cooperate to solve a problem.  As you know, if there is a junior partner who solves a problem, the others who is in this team are very happy. now,  K,G,J is in a team, if G solve a problems, K may say "G is 666666" or 
    J may say "23333, K is a doubi", And G say "K is a 2B23333".
       In these words ("G is 666666","23333, K is a doubi","K is a 2B23333"), there are many integers in these words. If I let the integers regroup and every digit only  appears only once. Can you help me find 
     the minimum values and the maximum value when I let the integers regroup. For example, "23333, K is a doubi", there are two kinds of digits which is 2 and 3. So after I let the integers regroup, the minimum values is 23 and the maximum value is 32.
       Now, you have to help us to find a strategy to minimum the expected number and maximize the expected number of correctly solved problems.

    Input

       The first line of the input is T (1 ≤ T ≤ 20), which stands for the number of test cases you need to solve.
       The next t line of each case contains a string s, whose length is len (len >= 0 && len <= 1000), 

    Output

    For each test case, print a line “Case t : Min Max”(without quotes, t means the index of the test case, Min and Max is the minimum values and the maximum value when I let the integers regroup).If no digits in the string, you can let the Min and Max is -1.

    Sample Input

    4
    do you think K is a doubi? 1 is yes
    doubi doubi doubi 23333333333
    we are the ACMers, we are on the way. 52 ACM!!!!!!!
    We love laowu! 233333 66666666

    Sample Output

    Case 1 : 1 1
    Case 2 : 23 32
    Case 3 : 25 52
    Case 4 : 236 632

    HINT

    There's no "0" at the beginning of the output if the answer contains not only "0". For example, output like "012" does not exist.


    You need use all digits which appeared in the input.



    分析:这个题目我可是走了大弯路了,仍然是小细节没有把握好,但思路不难。首先是接收并筛选数据,然后统计数据,最后按要求输出数据。

    这个题的细节很多:
    1.接收字符串的时候,因为中间有空格,所以不能用scanf只能用gets,但用gets又把上一个scanf的回车接收进来,所以需要使用fflush函数清空缓存,但这个函数在OJ中禁用,所以只能在scanf后面加入一个getchar()。但总感觉这也不是一个好方法。。。
    2.接收的字符串是char型的,需要转化为int型进
    #include <stdio.h>
     
    int main()
    {
        int T,t;
        char str[1024];
        int temp;
        int i,j,numcount,put0,put1;
     
        scanf("%d",&T);
        getchar();
        for(t=1;t<=T;t++)
        {
            int count[10]={0,0,0,0,0,0,0,0,0,0};
            numcount = 0;
            gets(str);
            for(i=0;str[i]!='';i++)
            {
                if(str[i]<='9' && str[i]>='0')
                {
                    temp = str[i]-'0';
                    count[temp]++;
                }
            }
     
            printf("Case %d : ",t);
            for(j=0;j<=9;j++)
            {
                if(count[j]!=0)
                    numcount++;
            }
            if(numcount==0)
                {printf("-1 -1
    ");continue;}
            if(count[0]!=0)
                put0 = 1;
            else
                put0 = 0;
            put1 = 0;
            for(j=1;j<=9;j++)
            {
                if(count[j]!=0)
                {
                    printf("%d",j);
                    while(put0)
                    {
                        printf("0");
                        put0 = 0;
                    }
                    put1++;
                }
            }
            if(!put1)
                printf("0");
            printf(" ");
            for(j=9;j>=0;j--)
            {
                if(count[j]!=0)
                    printf("%d",j);
            }
            printf("
    ");
        }
        return 0;
    }

    行处理。
    3.字符串没有数字时输出-1 -1。
    4.对于最大值,最小值的输出,就是分别按照数组正序和逆序分别输出。
    5.最小值中不能出现012,但是0还必须用,所以就是102(该开始以为是12,走了不少弯路)
  • 相关阅读:
    Linux Virtual Server技术
    log4j+slf4j迁移到log4j2+slf4j (Servlet3.0)
    Android控件ToggleButton的使用方法
    Redis学习手冊(事务)
    游戏server之server优化思路
    Codeforces 474D Flowers (线性dp 找规律)
    【C语言】编写函数实现库函数atof
    unity3D游戏开发实战原创视频讲座系列7之消消乐游戏开发
    [WebGL入门]二十一,从平行光源发出的光
    TwoSum leetcode
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312814.html
Copyright © 2011-2022 走看看