zoukankan      html  css  js  c++  java
  • FZU-2267 The Bigger the Better(字符串,模拟)

     Problem 2267 The Bigger the Better

    Accept: 132    Submit: 935
    Time Limit: 1500 mSec    Memory Limit : 32768 KB

     Problem Description

    Fat brother and Maze are playing a kind of special (hentai) game with two integers. All the digits of these two integers are in the range from 1 to 9. After they’ve got these two integers, they thought that these two numbers were not large enough! (You know that the young people always like the HUGE THING in order to have more pleasure) So they decide to use the digits of these two integers to make a new BIGGER integer. At the beginning of this game, the new integer has no digit, each time Fat Brother and Maze can choose one of the two initial integers (if this integer exists) and move its first digit to the end of the new integer. For instance, if the new integer is 233 and the two initial integers are 3154 and 1324 now, they can choose the first digit of the integer 3154, which is 3, and add it to the end of the new integer to make it become 2333. The two initial integers are 154 and 1324 now after this action. Also they can choose the first digit of the integer 1324 and add it to the end of the integer 233 and make it become 2331. This process goes until the two initial integers are all empty. Now Fat Brother and Maze would like to know the maximum number they could get after this special (hentai) game.

     Input

    The first line of the date is an integer T (1 <= T <= 102), which is the number of the text cases.

    Then T cases follow, each case contains two integers N and M (1 <= N,M <= 100000) indicated the number of the digits of these two integers. Then a line with N digits indicates the first integer and a line with M digits indicates the second integer. Note that all the digits are in the range from 1 to 9.

    In 90% of test cases, N, M <= 1000.

     Output

    For each case, output the case number first, and then output the integer Fat Brother and Maze would get, this integer should be as large as possible.

     Sample Input

    1 3 4 2 5 2 3 6 3 1

     Sample Output

    Case 1: 3632521

     Source

    第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)
    思路:字符串处理用strcmp函数
    代码:
    #include<stdio.h>  
    #include<iostream>  
    #include<string>  
    #include<string.h>  
    using namespace std;  
      
    int a,b;  
    string Q;  
    char A[100001],B[100001];  
      
    int main()  
    {  
        int t,n,m,k=1,s=1;  
        scanf("%d",&t);  
        while(t--)  
        {  
            char x,y;  
            Q="";  
            scanf("%d%d",&n,&m);  
            int ss=0;  
            for(int i=0; i<n; i++)  
            {  
                scanf("%d",&a);  
                A[ss++]=a+'0';  
                A[ss]='';  
            }  
            ss=0;  
            for(int i=0; i<m; i++)  
            {  
                scanf("%d",&b);  
                B[ss++]=b+'0';  
                B[ss]='';  
            }  
            printf("Case %d: ",s++);  
            int j=0,k=0,l=0;  
            while(j<n&&k<m)  
            {  
                x=A[j];  
                y=B[k];  
                if(x>y)  
                {  
                    j++;  
                    Q+=x;  
                }  
                else if(x==y)  
                {  
                    int temp=strcmp(A+j,B+k); ///从当前相等的位置开始比较  
                    if(temp>0)  
                    {  
                        while(j<n && A[j] == B[k])  
                            Q+=A[j++];  
                    }  
                    else  
                    {  
                        while(k<m && A[j] == B[k])  
                            Q+= B[k++];  
                    }  
                }  
                else  
                {  
                    k++;  
                    Q+=y;  
                }  
            }  
            if(j<n)  
            {  
                for(int i=j; i<n; i++)  
                    Q+=A[i];  
            }  
            if(k<m)  
            {  
                for(int i=k; i<m; i++)  
                    Q+=B[i];  
            }  
            cout<<Q<<endl;  
        }  
        return 0;  
    }  
    

      

     
  • 相关阅读:
    JAVA多线程实现的三种方式
    Java String charAt()方法
    三大数据库分页方法
    SSH框架 spring 配置中的: scope="prototype"
    SSH中的Invalid action class configuration that references an unknown class named.......
    String类中toCharArray()方法的用法
    SQL Server中DateTime与DateTime2的区别
    Java 集合系列11之 Hashtable详细介绍(源码解析)和使用示例
    Java 集合系列10之 HashMap详细介绍(源码解析)和使用示例
    哈希表及处理冲突的方法
  • 原文地址:https://www.cnblogs.com/luowentao/p/9000632.html
Copyright © 2011-2022 走看看