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]!='\0';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\n");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("\n");
    }
    return 0;
}

行处理。
3.字符串没有数字时输出-1 -1。
4.对于最大值,最小值的输出,就是分别按照数组正序和逆序分别输出。
5.最小值中不能出现012,但是0还必须用,所以就是102(该开始以为是12,走了不少弯路)
### 东科技大学数据结构期末考试复习指南 对于准备参加东科技大学数据结构期末考试的学生来说,了解考试形式和重点内容至关重要。根据往年的考试情况[^1],本学期的数据结构期末考试涵盖了多个重要方面: #### 考试概述 - **题型分布**:本次考试包括10道判断题、16道选择题以及三道函数题和两道编程题。 - **考试时间**:总时长为两个半小时。 #### 题目特点 - **基础题目为主**:大部分题目来源于平时作业,覆盖了从第一章的时间复杂度分析到最后一章的排序等内容。 - **难度适中**:相比前一年的试卷,整体难度有所降低,未涉及较为复杂的考研真题。 - **具体考点变化**:虽然今年的选择题没有涉及到KMP算法和关键路径的内容,但这并不意味着这些知识点不重要,在复习过程中仍需重视。 #### 关键知识点回顾 为了更好地应对可能出现在未来考试中的各类问题,建议重点关注以下几个方面的学习: - 时间复杂度计算方法及其应用实例; - 各种常见排序算法的工作原理及其实现方式; - 树形结构的操作,特别是关于二叉树的相关操作,比如删除特定子树等高级功能[^3]; ```cpp // 删除以x为根节点的子树示例代码 void removeSubtree(TreeNode* &root, int targetValue){ if (root == nullptr) return; // 如果当前结点是要移除的目标,则直接将其置为空并返回 if(root->val == targetValue){ deleteTree(root); root = nullptr; return; } // 递归处理左子树和右子树 removeSubtree(root->left ,targetValue); removeSubtree(root->right,targetValue); } // 辅助函数用于彻底清除整棵子树 void deleteTree(TreeNode*& node){ if(node != nullptr){ deleteTree(node->left ); deleteTree(node->right); delete node; node=nullptr; } } ``` 此段代码展示了如何通过递归来遍历整个二叉树,并找到指定值作为根节点的子树进行删除。需要注意的是,在实际编写程序时应当考虑边界条件和其他特殊情况下的正确性验证。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值