Min Number

Description
Now you are given one non-negative integer n in 10-base notation, it will only contain digits ('0'-'9'). You are allowed to choose 2 integers i and j, such that: i!=j, 1≤i<j≤|n|, here |n| means the length of n’s 10-base notation. Then we can swap n[i] and n[j].

For example, n=9012, we choose i=1, j=3, then we swap n[1] and n[3], then we get 1092, which is smaller than the original n.

Now you are allowed to operate at most M times, so what is the smallest number you can get after the operation(s)?

Input
The first line of the input contains an integer T (T≤100), indicating the number of test cases.

Then T cases, for any case, only 2 integers n and M (0≤n<10^1000, 0≤M≤100) in a single line.

Output
For each test case, output the minimum number we can get after no more than M operations.
Sample Input
3
9012 0
9012 1
9012 2
Sample Output
9012
1092
1029

1个回答

<div class="post-text" itemprop="text"> <p>I want to find the maximum and minimum value by the for loop, but problem is that when array value is start from a maximum number like (100,30,50,60) then output is the correct first maximum value then, minimum value. </p> <p>Otherwise output first minimum value, then maximum value. </p> <p>any idea?</p> <pre><code> //Number serial. \$number = array(10,15,20,100,25,30); for (\$i=0; \$i&lt;count(\$number); \$i++){ //Find maximum number by max function. if (\$number[\$i] == max(\$number)){ //Print maximum number. echo " The max number is \$number[\$i] &lt;br&gt;" ; } //Find minimum number by min function. elseif (\$number[\$i] == min(\$number)) { //Print minimum number. echo " The min number is \$number[\$i] &lt;br&gt;"; } } //Output: //The min number is 10 //The max number is 100 </code></pre> <p>When array value is start from a maximum number. </p> <pre><code> //Number serial. \$number = array(100,10,15,20,25,30); for (\$i=0; \$i&lt;count(\$number); \$i++){ //Find maximum number by max function. if (\$number[\$i] == max(\$number)){ //Print maximum number. echo " The max number is \$number[\$i] &lt;br&gt;" ; } //Find minimum number by min function. elseif (\$number[\$i] == min(\$number)) { //Print minimum number. echo " The min number is \$number[\$i] &lt;br&gt;"; } } //Output: //The max number is 100 //The min number is 10 </code></pre> </div>

CursorIndexOutOfBoundsException

CursorIndexOutOfBoundsException: Index 118 requested, with a size of 118 在数据库中是有第118号元素，但如果调用118号元素就会出错，minNumber是上界，maxNumber是下界，求解？ ``` float maxBuffer = 0; float minBuffer =999999999; chemicalCursor.moveToPosition(this.minNumber); for(int i=this.minNumber;i<=this.maxNumber;i++) { if (chemicalCursor.moveToFirst()) { float numberBuffer = chemicalCursor.getFloat(chemicalCursor.getColumnIndex(this.columnName)); Log.d("Buffer",numberBuffer+""); if(numberBuffer>maxBuffer){ maxBuffer = numberBuffer; Log.d("Buffer"," "+maxBuffer); } if(numberBuffer<minBuffer){ minBuffer = numberBuffer; Log.d("Buffer"," "+minBuffer); }} ```

C语言用函数求最大公约数和最小公倍数，看不出错在哪，代码如下

#include<stdio.h> int maxnumber(int x,int y) { int a=0; a=x%y; while(a!=0) { a=x%y; x=y; y=a; } return y; } int minnumber(int x,int y) { int z; z=(x*y)/maxnumber(x,y); return z; } void main() { int maxnumber(int x,int y); int minnumber(int x,int y); int a=0,b=0,c,d; printf("请输入两个数\n"); scanf("%d%d",&a,&b); c=maxnumber(a,b); d=minnumber(a,b); printf("最大公约数为%d\n",c); printf("最小公倍数为%d\n",d); }

<div class="post-text" itemprop="text"> <p>So I have a table in mysql that has on it columns for a Minimum number and a maximum number.</p> <pre><code>| ID | MinNumber | MaxNumber | | 1 | 2 | 4 | | 2 | 3 | 7 | | 3 | 10 | 12 | </code></pre> <p>I want to get a list of numbers that is included in all ranges.</p> <p>So the list should look like: <code>2, 3, 4, 5, 6, 7, 10, 11, 12</code> Notice that 8 and 9 are missing because they are not within a range on the table.</p> <p>Is there an easy way to get this range?</p> <p>If it helps, I am trying to do this using PHP.</p> <p>EDIT: This needs to run optimally. The real table has over 200,000 rows in it and the ranges can be hundreds apart. Any way to cut down on the processing time for this would help a lot!</p> </div>

#include<stdio.h> int main() { int a[10],i,max,min,p_max=0,p_min=0; for(i=0;i<10;i++) scanf("%d",&a[i]); max=a[0]; min=a[0]; for(i=1;i<10;i++) { if(a[i]>max) { max=a[i]; p_max=i+1; } if(a[i]<min) { min=a[i]; p_min=i+1; } }printf("No.%d is the max number %d\n",p_max,max); printf("No.%d is the min number %d\n",p_min,min); } 为什么p_min是0啊？新手求解答

<div class="post-text" itemprop="text"> <p>I'm looking for a way to generate random string between min and max number of characters using laravel Faker. I have to create random strings between <code>4</code> and <code>20</code> characters. This method <code>str_random</code> will generate exactly 20 characters, but how to specify min number of characters?</p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php use Faker\Generator as Faker; \$factory-&gt;define(App\User::class, function (Faker \$faker) { return [ 'name' =&gt; str_random(20), ]; });</code></pre> </div> </div> <p>Updated: I'm using the following code now as a workaround:</p> <pre><code>'name' =&gt; substr(\$faker-&gt;name(), 0, rand(4, 20)) </code></pre> </div>

``` #include<stdio.h> #define N 4 void min(int (*a)[N],int m) /*自定义min函数，求二维数组中每行最小元素*/ { int value,i,j; for(i=0;i<m;i++) { value=*(*(a+i)); /*将每行中的首个元素赋给value*/我的理解：这里a+i表示第i行的首地址，加一个*就指向首地址的变量了，为什么最外层还有一个*？ for(j=0;j<N;j++) if(*(*(a+i)+j)<value) /*判断其他元素是否小于value的值*/ value=*(*(a+i)+j); /*把比value小的数重新赋给value*/ printf("line %d:the min number is %d\n",i,value); } } main() { int a[3][N],i,j; int (*p)[N]; p=&a[0]; printf("please input:\n"); for(i=0;i<3;i++) for(j=0;j<N;j++) scanf("%d",&a[i][j]); /*给数组中的元素赋值*/ min(p,3); /*调用min函数，指针变量作函数参数*/ } ```

<div class="post-text" itemprop="text"> <p>I have the following array:</p> <pre><code>Array ( [0] =&gt; 124,95 [1] =&gt; 139,95 [2] =&gt; 149,95 [3] =&gt; 1200 [4] =&gt; 150 [5] =&gt; 154,95 [6] =&gt; 130 [7] =&gt; 189,95 [8] =&gt; 199,95 [9] =&gt; 30 [10] =&gt; 150 ) </code></pre> <p>And I am trying to get the lowest (30) and highest (1200) numbers from it.</p> <p>So I did this:</p> <pre><code>while(\$getpricesproducts = \$getpricesproductscon-&gt;fetch_assoc()){ \$prijsarray[] = \$getpricesproducts['prijs']; } // Lowest and highest price to put in price slider \$prijslow = min(\$prijsarray); \$prijshigh = max(\$prijsarray); echo \$prijslow; echo \$prijshigh; </code></pre> <p><code>\$prijsarray</code> is above array.</p> <p>But the echoed values are 30 as min number and 150 as max. Why is that? Does it have something to do with the commas in some numbers? Still it is weird that 1200 is not the max number since it does not have any commas.</p> </div>

PHP脚本变量表现奇怪

<div class="post-text" itemprop="text"> <p>Script: (too large, didn't want to paste it and clutter this, sorry.) </p> <p><a href="http://pastebin.com/jhvgAqzj" rel="nofollow">http://pastebin.com/jhvgAqzj</a></p> <p>Well, for some reason \$p is acting very very weird, the \$p is set to 1 and should add 1 to itself when the 'next' button is pressed. Inversely should subtract 1 from \$p when the 'prev' button is pressed.</p> <p>There are also 2 nested 'if' statements to prevent it from ever going over the max number or pictures, or under the min number of pictures.</p> <p>\$p is the variable used to display the picture according to its ID type. </p> <p>For some reason, it will work until you get to picture 3, when you hit next, the variable jumps to 2. When you hit previous on 2, it jumps to 3. </p> <p>This is very confusing but we laughed when we tested it.</p> <p>Thanks for the help in advance!</p> </div>

<div class="post-text" itemprop="text"> <p>I know there are similar people that posted contact form help but I have an issue with mine. Everything works but when I submit I get an e-mail from apache that shows a blank message. However, when I use my own e-mail address in the form input , it works. </p> <p>Here is my code</p> <pre><code>&lt;?php if(isset(\$_POST['submit'])){} \$name = \$_POST['name']; \$email = \$_POST['email']; \$minrooms=\$_POST['mrooms']; \$message = \$_POST['comment']; \$formcontent="From: \$name Email: \$email Min Number of Rooms: \$minrooms Message: \$message "; \$recipient = "kellito13@gmail.com"; \$subject = "Contact Form"; \$mailHeader = "From: \$email "; send_contact= mail(\$recipient, \$subject, \$formcontent, \$mailHeader) or die("Error!"); echo "Thank You!"; } else{ echo"Error"; } ?&gt; </code></pre> </div>

``` number=[1,5,2,26,3,-1] def findMaxandMin(number): min=number[0] max=number[0] for x in number: if x>max : max=x if x<min : min=x return(min,max) print(findMaxandMin(number)) ```

input type="number" 定义默认值

``` <input class="form-control" type="number" name="points" value="1" min="1" data-ng-model="NoticeEditor.obj.limitation" /> ``` 设置默认值为1，不好使啊

oracle中number类型转换

to_char(min(a.l_entrust_time),'HH24:mm:ss') 其中a.l_entrust_time在数据库中为number类型,如：140930，想转为14:09:30应该怎么转换

ASP.NET2.0重写TextBox控件属性type=number

Parameter index out of range (2 > number of parameters, which is 1)

python问题There should be number after

#!/usr/bin/env python import rrdtool import time title="Server network traffic flow ("+time.strftime('%Y-%m-%d',time.localtime(time.time()))+")" "MINUTE:12" "HOUR:1" "HOUR:1" "0:%H" rrdtool.graph( "Flow.png", "--start","-ld","--vertical-lable=Bytes/s", "--x-grid","MINUTE:12:HOUR:1:HOUR:1:0:%H", "--width","650","--height","230","--title",title, "DEF:inoctets=Flow.rrd.eth0_in:AVERAGE", "DEF:outoctets=Flow.rrd:eth0_out:AVERAGE", "CDEF:total=inoctets,outoctets,+", "LINE1:total#FF8833:Total traffic", "AREA:inoctets#00FF00:In traffic", "LINE1:outoctets#0000FF:Out traffic", "HRULE:6144#FF0000:Alarm value\\r", "CDEF:inbits=inocets,8,*", "CDEF:outbits=outoctets,8,*", "COMMENT:\\r", "COMMENT:\\r", "GPRINT:inbits:AVERAGE:Avg In traffic\: %6.21f %Sbps", "COMMENT: ", "GPRINT:inbits:MAX:Max In traffic\: %6.21f %Sbps", "COMMENT: ", "GPRINT:inbits:MIN:MIN In traffic\: %6.21f %Sbps\\r", "COMMENT: ", "GPRINT:outbits:AVERAGE:Avg Out traffic\: %6.21f %Sbps", "COMMENT: ", "GPRINT:outbits:Max:Max Out traffic\: %6.21f %Sbps", "COMMENT: ", "GPRINT:outbits:MIN:MIN Out traffic\: %6.21f %Sbps" ) 最后一行报错rrdtool.OperationalError: start time: There should be number after '-' 求大神解答一下，不胜感激

Theano 报错：Wrong number of dimensions...

Java基础知识面试题（2020最新版）

Intellij IDEA 实用插件安利

1. 前言从2020 年 JVM 生态报告解读 可以看出Intellij IDEA 目前已经稳坐 Java IDE 头把交椅。而且统计得出付费用户已经超过了八成（国外统计）。IDEA 的...

MySQL数据库面试题（2020最新版）

2020阿里全球数学大赛：3万名高手、4道题、2天2夜未交卷

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...

Python爬虫，高清美图我全都要（彼岸桌面壁纸）

Vue回炉重造之router路由（更新中）

Java岗开发3年，公司临时抽查算法，离职后这几题我记一辈子