zoukankan      html  css  js  c++  java
  • nyoj---t448(寻找最大数)

     

    描述

    请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大,

    比如当n=92081346718538,m=10时,则新的最大数是9888

     

     
    输入
    第一行输入一个正整数T,表示有T组测试数据
    每组测试数据占一行,每行有两个数n,m(n可能是一个很大的整数,但其位数不超过100位,并且保证数据首位非0,m小于整数n的位数)
    输出
    每组测试数据的输出占一行,输出剩余的数字按原次序组成的最大新数
    样例输入
    2
    92081346718538 10
    1008908 5
    样例输出
    9888
    98
    #include <stdio.h>
    #include <string.h>
    int main()
    {
    	int t,m,n,q;
    	char ans[105],s[105];
    	int max;
    	int i,x;
    	scanf("%d",&t);
    	while (t--)
    	{
    		//memset(a,0,sizeof(a));
    		scanf("%s%d",s,&m);
    		n = strlen(s);
    		for (i=0,q=-1;i<n-m;i++)
    		{
    			max = 0;
    			//x = cmp(a,n);
    			for(int j=q+1;j<=m+i;j++)
    				if(max < s[j])
    					max = s[j] , q = j;
    			ans[i] = max;
    		}
    		/*for(i=0;i<n;i++)
    			if(a[i]!='a')
    				printf("%c",a[i]);
    			printf("
    ");*/
    		ans[n-m] = '';
    		puts(ans);
    	}
    	return 0;
    }
    

     

     
    #include <stdio.h>
    #include <iostream>
    using namespace std;
    #include <string.h>
    int cmp(char a[],int n)
    {
    	int i,x;
    	char m;
    	m = a[n-1];
    	x=n-1;
    	for (i=n-2;i>=0;i--)
    	{
    		if (m>=a[i])
    		{
    			m = a[i];
    			x = i;
    		}
    	}
    	return x;
    }
    int main()
    {
    	int t,m,n;
    	char a[110];
    	int i,x;
    	scanf("%d",&t);
    	while (t--)
    	{
    		memset(a,0,sizeof(a));
    		scanf("%s%d",a,&m);
    		n = strlen(a);
    		for (i=0;i<m;i++)
    		{
    			x = cmp(a,n);
    			a[x] = '@';
    		}
    		for(i=0;i<n;i++)
    			if(a[i]!='@')
    				printf("%c",a[i]);
    			printf("
    ");
    	}
    	return 0;
    }
            



    同样的结果,不同的是能不能通过提交。ACM的思想是很关键的,然后需要严谨的步骤,不能出现丁点的错误,所以继续努力吧。向大牛看齐。



  • 相关阅读:
    python,生产环境安装
    neo4j 图数据库
    RNN系列
    机器学习关于AUC的理解整理
    fensorflow 安装报错 DEPENDENCY ERROR
    dubbo Failed to check the status of the service com.user.service.UserService. No provider available for the service
    使用hbase遇到的问题
    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk
    gradle 安装
    jenkins 安装遇到的坑
  • 原文地址:https://www.cnblogs.com/acmwangpeng/p/5524896.html
Copyright © 2011-2022 走看看