zoukankan      html  css  js  c++  java
  • 新生赛3 1003 字符串最小表示法题目

    Problem C

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 43   Accepted Submission(s) : 11

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    Problem Description

    Recently, Tom did a research in 62-system number(0~9,A~Z,a~z mean 0~9, 10~35, 36~61 respectively). He wrote two 62-system numbers in two cards and asked bb and dd to choose one, dd always choose the first. Each of them can rotate the number to make the number minimum. ( after abc is rotated, the string changes like(abc->cab->bca->abc), certainly bb and dd will choose the smallest one )
    The one that gets the smaller number wins. 

    Input

    The first line of the input is an integer T, which means there are exactly T cases in the input.
    Each test case contain two strings(the first is the number dd chose , both are shorter than 10001)

    Output

    If dd wins output"dd", and if bb wins outputs "bb", otherwise outputs "ddbb".

    Sample Input

    1
    0aab0
    00aac
    

    Sample Output

    dd
    
    直接贴代码了
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    char A1[10002],B1[10002];
    int A[20002],B[20002];
    int lena,lenb;
    int input()
    {
    		int i;
    		gets(A1);
    		gets(B1);
    		lena=strlen(A1);
    		lenb=strlen(B1);
    		for(i=0;i<lena;i++)
    		if('0'<=A1[i]&&A1[i]<='9')
    		A[i+lena]=A[i]=A1[i]-'0';
    		else if('A'<=A1[i]&&A1[i]<='Z')
    		A[i+lena]=A[i]=A1[i]-'A'+10;
    		else if('a'<=A1[i]&&A1[i]<='z')
    		A[i+lena]=A[i]=A1[i]-'a'+36;
    		for(i=0;i<lenb;i++)
    		if('0'<=B1[i]&&B1[i]<='9')
    		B[i+lenb]=B[i]=B1[i]-'0';
    		else if('A'<=B1[i]&&B1[i]<='Z')
    		B[i+lenb]=B[i]=B1[i]-'A'+10;
    		else if('a'<=B1[i]&&B1[i]<='z')
    		B[i+lenb]=B[i]=B1[i]-'a'+36;
    		return 0;
    }
    int MinimumRepresentation(int *s, int l)  
    {  
    	int i,j,k;
    	i=0;j=1;k=0;
    	while(i<l&&j<l)
    	{
    		k=0;
    		while(s[i+k]==s[j+k]&&k<l) k++;
    		if(k==l) return i;
    		if(s[i+k]>s[j+k]) 
    		 if(i+k+1>j) i=i+k+1;
    		 else i=j+1;
    		else if(j+k+1>i) j=j+k+1;
    		else  j=i+1; 
    	}
    	if(i<l) return i;
    	else return j;
    } 
     
    int compare(int s,int S)
    {
    	int i=s,I=S;
    	do
    		{
    			if(A[i]>B[I]) return 1;
    			else if(A[i]<B[I]) return -1;
    			i++;
    			I++;
    		}
    		while((i-s)!=(lena-1)&&(I-S)!=(lenb-1));
    	if((i-s)==(lena-1)&&(I-S)==(lenb-1)) return 0;
    	else if((i-s)==(lena-1)) return -1;
    	else if((I-S)==(lenb-1)) return 1;
    	 
    }
    int main()
    {
    	int T,k1,k2,k3;
    	scanf("%d",&T);
    	gets(A1);
    	while(T--)
    	{
    		input();
    		k1=MinimumRepresentation(A,lena);
    		k2=MinimumRepresentation(B,lenb);
    		k3=compare(k1,k2);
    		if(k3==1) printf("bb
    ");
    		else if(k3==0) printf("ddbb
    ");
    		else if(k3==-1) printf("dd
    ");
    	}
    		return 0;
    }



  • 相关阅读:
    【洛谷P6139】【模板】广义后缀自动机(广义 SAM)
    【CF700E】Cool Slogans
    【CF605E】Intergalaxy Trips
    【洛谷P3638】机器人
    【洛谷P4762】Virus synthesis
    Web前端从入门到精通-8 css简介——清除浮动
    Web前端从入门到精通-7 css简介——浮动
    Web前端从入门到精通-6 css简介——选择器优先级
    Web前端从入门到精通-5 css简介——css概述和选择器
    Web前端从入门到精通-4 html简介
  • 原文地址:https://www.cnblogs.com/zy691357966/p/5480471.html
Copyright © 2011-2022 走看看