代码高尔夫:三个整数的所有+-*/组合

31

编写一个程序,接受由空格分隔的3个整数,并对所有可能的加法、减法、乘法和除法操作执行每个组合,显示使用的操作组合及其结果。

示例:

$./solution 1 2 3

输出如下:

1+2+3 = 6

1-2-3 = -4

1*2*3 = 6

1/2/3 = 0(只显示整数答案,.5及以上四舍五入)

1*2-3 = -1

3*1+2 = 5

等等...

按照操作顺序规则执行,假设不会使用括号,例如(3-1)*2=4不算作一种组合,但您可以为“额外积分”实现此操作。

对于出现除以0的结果,请返回NaN。

编辑:需要对输入进行排列,即如果输入为1 2 3,则3*1*2是一种有效的组合。


5
@Flash:请遵循http://meta.stackexchange.com/questions/24242/acceptable-level-of-code-golf-questions/24258#24258中描述的规范。 - kennytm
并不是非常清楚重新排列输入数字也是必要的。澄清这一点可能会有所帮助。 - David
1
我不确定,但这难道不有点不公平吗?因为它在大多数解释型语言中都可以极大地受益于内置的 eval() 函数。 - Alexander Gessler
1
@Alexander:这个C语言示例表明,预处理器可以被滥用来进行eval操作。 - SztupY
@Alexander,@SztupY:Java 的邪恶性质也可以被滥用。真的! - Pindatjuh
我最近也遇到了这个问题,用C#写了一个非eval方法。不过使用eval会更容易些。 - Matt Mitchell
17个回答

26

Perl 130个字符

只要允许使用外部库:

use Algorithm::Permute"permute";
permute{for$x(@a=qw(+ - / *)){for$y(@a){$_="@ARGV";s/ /$x/;s/ /$y/;printf"
$_ = %.0f",eval}}}@ARGV

第二个换行符是有意义的。

没有使用模块,并且假设三个输入都不同,这里是另一个解决方案:

      @n=&             ARGV;
      @o=(            q[+],
      "-",           q{/},         '*'     );;
      for$          {a}(@           n){   for
 $b(@n){for$c(@    {n}){             for $x( 
 @o){for$y(@o){   ($a-$  b)*($a-$c)*  ($b-$
 c)||next;$_=$a  .$x.$   b."$y$c";$%   =42
      /84+      eval;    print"",$_,  "$S="
      ,$S,     $%,$/                 }}} }};
      ;sub    ARGV{                 $S=   $".
      "";@   ARGV}                 ;1+     2+3

21

Java - 666个字符

还有单行代码,幸运的是我们有Eclipse和Netbeans自动代码格式化! :-) 还实现了括号(但也包含了琐碎的操作)?

public class CodeGolf{static String[]o={"+","-","/","*"};static void p(N a,int b,N c,int d,N e,int i){System.out.printf("%s%s(%s%s%s) = %s\n",a,o[b],c,o[d],e,new N(a,b,new N(c,d,e)));}public static void main(String[]v){N[]n={new N(v[0]),new N(v[1]),new N(v[2])};for(int i=0,j=0,k=0,l=0,m=0;m<3;i++,j+=i==4?1:0,i%=4,k+=j==4?1:0,j%=4,l+=k==3?1:0,k%=3,m+=l==3?1:0,l%=3){p(n[k],i,n[l],j,n[m],0);}}static class N{Double v;N(String s){v=v.parseDouble(s);}N(N a,int o,N b){if(a.v==null||b.v==null)return;double x=b.v, y=a.v; switch(o){case 0:x=-x;case 1:v=y-x;return;case 3:v=y*x;x=0;case 2:if(x!=0)v=y/x;}}public String toString(){return v!=null?""+Math.round(v):"NaN";}}}

扩展、格式化并附有注释的版本:

public class CodeGolf {

// operators
static String[] o = {"+", "-", "/", "*"};

// print
static void p(N a, int b, N c, int d, N e, int i) {
    System.out.printf("%s%s(%s%s%s) = %s\n", a, o[b], c, o[d], e,
            new N(a, b, new N(c, d, e))); // calculate
}

public static void main(String[] v) {
    N[] n = {new N(v[0]), new N(v[1]), new N(v[2])};
    // Nested for-loops? Nah, too much code!
    // Conditional operator, modulus is way cooler.
    for (int i = 0, j = 0,
             k = 0, l = 0, m = 0; m < 3; i++,
                                    j += i == 4 ? 1 : 0,
                                         i %= 4,
                               k += j == 4 ? 1 : 0,
                                    j %= 4,
                          l += k == 3 ? 1 : 0,
                               k %= 3,
                     m += l == 3 ? 1 : 0,
                          l %= 3) {
        p(n[k], i, n[l], j, n[m], 0);
    }
}

// number wrapper
static class N {

    Double v;

    // parse input
    N(String s) {
        v = v.parseDouble(s);
    }

    // calculate input
    N(N a, int o, N b) {
        // NaN's should fall through
        if (a.v == null || b.v == null) {
            return;
        }
        double x = b.v, y = a.v;
        // operator execution
        switch (o) {
            case 0:
                x = -x;
                // fall through; y + x = y - (-x)
            case 1:
                v = y - x;
                return; // break would make it 665 characters, not as cool
            case 3:
                v = y * x;
                x = 0;
                // fall through; no return needed
            case 2:
                if (x != 0) {
                    v = y / x;
                }
                // will NaN because v = null if x = 0
        }
    }

    // rounding and NaN
    public String toString() {
        return v != null ? "" + Math.round(v) : "NaN";
    }
}

}

对两个操作数(4 * 4)进行迭代,对操作数进行排列组合两次(3!* 2),总共有(4 * 4 * 3 * 2 * 2 = 192)种可能性。

+ /- 2.5小时 :-) 祝您愉快!


17
那是我见过的最邪恶的“for”循环! - Esko

17

Delphi - 838 747个字符

单行版本(原始)

program p;{$APPTYPE CONSOLE}uses SysUtils;type g=Integer;function a(b,c:g):g;begin a:=b+c;end;function s(b,c:g):g;begin s:=b-c;end;function m(b,c:g):g;begin m:=b*c;end;function d(b,c:g):g;begin d:=b div c;end;type t=function(b,c:g):g;r=record f:t;c:char;p:boolean;end;procedure q(l:Array of g;w,e:r);var b:String;x,y,z:g;begin for x:=0 to 2 do for y:=0 to 2 do for z:=0 to 2 do if not((x=y)or(x=z)or(y=z))then begin try if(w.p)or not(w.p xor e.p)then b:=IntToStr(e.f(w.f(l[x],l[y]),l[z]))else b:=IntToStr(w.f(l[x],e.f(l[y],l[z])));except b:='NaN';end;writeln(l[x],w.c,l[y],e.c,l[z],'=',b);end;end;const O:Array[0..3]of r=((f:a;c:'+';p:false),(f:s;c:'-';p:false),(f:m;c:'*';p :true),(f:d;c:'/';p:true));var L:Array[0..2] of g;I,J:g; begin for I:=0 to 2 do L[I]:=StrToInt(ParamStr(I+1));for I:=0 to 3 do for J:=0 to 3 do q(l,o[I],o[J]);end.

单行版本(缩短至747个字符)

program p;{$APPTYPE CONSOLE}uses SysUtils,Math;type g=integer;t=function(b,c:g):g;r=record f:t;p:boolean;end;function a(b,c:g):g;begin a:=b+c end;function s(b,c:g):g;begin s:=b-c end;function m(b,c:g):g;begin m:=b*c end;function d(b,c:g):g;begin d:=b div c end;const f=true;u=false;n=[1..4];b=[1..3];c='+-*/';O:Array[1..4]of r=((f:a;p:f),(f:s;p:f),(f:m;p:u),(f:d;p:u));var l: Array[1..3]of g;I,J,x,y,z:g;w,e:r;begin for I in b do l[I]:=StrToInt(ParamStr(I));for I in n do for J in n do for x in b do for y in b do for z in b do if not((x=y)or(x=z)or(y=z))then begin w:=O[I];e:=O[J];write(l[x],c[I],l[y],c[J],l[z],'=');try writeLn(ifthen(w.p or not(w.p xor e.p),e.f(w.f(l[x],l[y]),l[z]),w.f(l[x],e.f(l[y],l[z]))))except writeln('NaN')end;end;end.

格式化:

program p;
{$APPTYPE CONSOLE}
uses SysUtils;

type
  g = Integer;

function a(b, c: g): g;
begin
  a := b + c;
end;

function s(b, c: g): g;
begin
  s := b - c;
end;

function m(b, c: g): g;
begin
  m := b * c;
end;

function d(b, c: g): g;
begin
  d := b div c;
end;

type
  t = function(b, c: g): g;

  r = record
    f: t;
    c: char;
    p: boolean;
  end;

procedure q(l: Array of g; w, e: r);
var
  b: String;
  x, y, z: g;
begin
  for x := 0 to 2 do
    for y := 0 to 2 do
      for z := 0 to 2 do
        if not((x = y) or (x = z) or (y = z)) then
        begin
          try
            if (w.p) or not(w.p xor e.p) then
              b := IntToStr(e.f(w.f(l[x], l[y]), l[z]))
            else
              b := IntToStr(w.f(l[x], e.f(l[y], l[z])));
          except
            b := 'NaN';
          end;
          writeln(l[x], w.c, l[y], e.c, l[z], '=', b);
        end;
end;

const
  O: Array [0..3] of r = ((f: a; c: '+'; p: false), (f: s; c: '-'; p: false),
                            (f: m; c: '*'; p: true), (f: d; c: '/'; p: true));

var
  l: Array [0..2] of g;
  I, J: g;
begin

  for I := 0 to 2 do
    l[I] := StrToInt(ParamStr(I + 1));
  for I := 0 to 3 do
    for J := 0 to 3 do
      q(l, O[I], O[J]);

end.

这绝对是我写过的最丑陋的代码。


别担心,我已经把它搞得更糟了,以消除91个字符 :) - Wouter van Nifterick
你仍然可以删除"program"行,因为编译器不需要它,并且可以在命令行中使用编译器开关来去掉"APPTYPE"。 - Uwe Raabe

16

J,75个55字符。

输出的是有理数而不是整数。

(],"1'=',"1 ":@x:@".)((' ',>@{.),@,.":"0@>@{:)"1>{(,{;~'+-*%');<<"1(i.!3)A.

旧版本未对输入进行排列(长度为55个字符)

(],"1'=',"1 ":@x:@".)(>,{;~'+-*%')(' 'I.@:E.s)}"1 s=:":

示例(请注意,J语言的运算顺序是从右到左):

   (],"1'=',"1 ":@x:@".)((' ',>@{.),@,.":"0@>@{:)"1>{(,{;~'+-*%');<<"1(i.!3)A.1 2 3
 1+2+3=6   
 1+3+2=6   
 2+1+3=6   
 2+3+1=6   
 3+1+2=6   
 3+2+1=6   

 1+2-3=0   
 1+3-2=2   
 2+1-3=0   
 2+3-1=4   
 3+1-2=2   
 3+2-1=4   

 1+2*3=7   
 1+3*2=7   
 2+1*3=5   
 2+3*1=5   
 3+1*2=5   
 3+2*1=5   

 1+2%3=5r3 
 1+3%2=5r2 
 2+1%3=7r3 
 2+3%1=5   
 3+1%2=7r2 
 3+2%1=5   

 1-2+3=_4  
 1-3+2=_4  
 2-1+3=_2  
 2-3+1=_2  
 3-1+2=0   
 3-2+1=0   

 1-2-3=2   
 1-3-2=0   
 2-1-3=4   
 2-3-1=0   
 3-1-2=4   
 3-2-1=2   

 1-2*3=_5  
 1-3*2=_5  
 2-1*3=_1  
 2-3*1=_1  
 3-1*2=1   
 3-2*1=1   

 1-2%3=1r3 
 1-3%2=_1r2
 2-1%3=5r3 
 2-3%1=_1  
 3-1%2=5r2 
 3-2%1=1   

 1*2+3=5   
 1*3+2=5   
 2*1+3=8   
 2*3+1=8   
 3*1+2=9   
 3*2+1=9   

 1*2-3=_1  
 1*3-2=1   
 2*1-3=_4  
 2*3-1=4   
 3*1-2=_3  
 3*2-1=3   

 1*2*3=6   
 1*3*2=6   
 2*1*3=6   
 2*3*1=6   
 3*1*2=6   
 3*2*1=6   

 1*2%3=2r3 
 1*3%2=3r2 
 2*1%3=2r3 
 2*3%1=6   
 3*1%2=3r2 
 3*2%1=6   

 1%2+3=1r5 
 1%3+2=1r5 
 2%1+3=1r2 
 2%3+1=1r2 
 3%1+2=1   
 3%2+1=1   

 1%2-3=_1  
 1%3-2=1   
 2%1-3=_1  
 2%3-1=1   
 3%1-2=_3  
 3%2-1=3   

 1%2*3=1r6 
 1%3*2=1r6 
 2%1*3=2r3 
 2%3*1=2r3 
 3%1*2=3r2 
 3%2*1=3r2 

 1%2%3=3r2 
 1%3%2=2r3 
 2%1%3=6   
 2%3%1=2r3 
 3%1%2=6   
 3%2%1=3r2 

整数答案只会在.5时四舍五入。 - Robert Love

10

C语言

该语言的代码占用磁盘空间为600字节,使用DOS换行符。

#define C B a,B b
#define D(N,O)B N(C){return a O b;}
#define E(A,B,C)i=A;j=B;k=C;X(m,p)X(m,m)X(t,t)X(d,t)X(t,d)X(d,d)Y(m,p)Y(p,p)Y(p,t)Y(p,d)Y(m,t)Y(m,d)
#define U"%.0f"
#define P(S,T)printf(U Z(S)U Z(T)U"="U"\n",v[i],v[j],v[k],
#define p +
#define m -
#define t *
#define d /
#define X(S,T)P(S,T)f##S(f##T(v[i],v[j]),v[k]));
#define Y(S,T)P(S,T)f##S(v[i],f##T(v[j],v[k])));
#define Z(A)#A
typedef double B;D(fp,+)D(fm,-)D(ft,*)B fd(C){return b?(int)(a/b+.5):-0.0;}main(int i,char*b[]){int j,k;B v[3]={atoi(b[1]),atoi(b[2]),atoi(b[3])};E(0,1,2)E(0,2,1)E(1,0,2)E(1,2,0)E(2,0,1)E(2,1,0)}

C语言似乎没有NaN字面量,所以如果有任何问题,你会得到-0而不是NaN。然而,我认为它在其他方面都适合。请注意,数据类型是“double”,因此如果其中包含NaN,则通过printf打印出来的也会是NaN。

7
+1 预处理器的滥用。但是你能否在不包含头文件的情况下使用 atoi?或者 printf?我的 GCC 不支持它。 - walkytalky
虽然它们没有声明,但这没关系,因为两者实际上都返回int,并且提供的参数与例程所期望的相匹配。你遇到了什么错误?(为了获得最佳结果,我猜应该编译为C89,关闭有关未声明函数的警告;我不使用gcc,所以无法确定。尽管看起来很复杂,但实际上并没有什么棘手的地方...) - please delete me
你是对的,它们只是警告。对于第4行:“宏名称后缺少空格”;对于第13行:“printf的不兼容隐式声明内置函数”。生成的可执行文件运行良好。 - walkytalky

6

Javascript,169个字符

(不包括不必要的换行和缩进)

编辑:现在带有输入排列

o=" ";i=i.split(o);z="+-*/";for(y=0;y<27;y++)for(x=0;x<16;x++){a=y/9|0;b=(y/3|0)%3;c=y%3;if(a!=b&&a!=c&&b!=c){s=i[a]+z[x/4|0]+i[b]+z[x%4]+i[c];o+=s+"="+~~(eval(s)+.5);}}

缩进的代码:

o=" ";
i=i.split(o);
z="+-*/";
for(y=0;y<27;y++)
for(x=0;x<16;x++)
{
    a=y/9|0;
    b=(y/3|0)%3;
    c=y%3;
    if(a!=b&&a!=c&&b!=c)
    {
        s=i[a]+z[x/4|0]+i[b]+z[x%4]+i[c];
        o+=s+"="+~~(eval(s)+.5);
    }
}

你可以去掉不必要的格式(HTML方面),并且再减少一些字符。 - Malfist
到目前为止,这是唯一一个没有硬编码输入的。 - Malfist
2
但是它在哪里对输入进行排列组合呢? - SztupY
1
问题的复杂性部分在于表达式的评估。如果使用内置函数来完成它,那么你就错过了问题的一半。这也是对于那些没有 eval 函数的语言不公平的优势。请参阅此讨论:http://meta.stackexchange.com/questions/24242/acceptable-level-of-code-golf-questions/24258#24258 - Thomas Levesque
3
嗯?什么?使用特定语言的特点是不公平的吗?如果只能使用它们共同的特点,为什么还要选择一种语言呢?整个重点就是创造性地选择一种语言和方法,以使用最少数量的字符。 - Beska
1
我认为这个问题本身有点违反了那个质量点(没有简单的内置解决方案),但这并不使答案无效。 - Eric Mickelsen

6

Python - 177个字符:

(不再计算缩进)
增加了命令行输入,不再限制为单个数字或非零数字,可以使用零(NaN)。

import sys
from itertools import permutations as p
for i,j,k in p(sys.argv[1:4],3):
    for x,y in p('+-*/'*2,2):
        s=i+x+j+'.'+y+k
        try:e=eval(s)
        except:e='NaN'
        print s,'=',e

还有 不再将0.5截断而是四舍五入


14
我认为在Python中不应省略缩进,因为它们是很重要的。 - kennytm
1
-1:无法在当前形式下处理其输入中的 0(或具有多个数字的值,例如 15)。 - ChristopheD
当你计算(必须!)换行和缩进时,实际上它是134个字符。在Python <2.6中不起作用。此外,这3个值是硬编码的,只能是单个数字。 - Nas Banov
我从一开始就在答案中提到了截断问题。Python 2.5的兼容性与代码高尔夫有什么关系? - tzaman
截断结果(所以9/10将变为0而不是1)。查看我的解决方案,了解“浮点”的想法。或者可以使用eval(s.replace('/','./')) - 因为问题只涉及除法,添加小数点将操作数转换为浮点数。 - Nas Banov

4

Bash shell, 140个字符

应该适用于任何半现代的Bash(已在GNU bash 3.2.48(1)x86_64-apple-build中进行了测试)。

处理除零操作(Nan情况)。

欢迎所有建议和评论!

for a in $@;do
s+={`echo $@|tr ' ' ,`}{+,-,*,/};done
for i in `eval echo ${s::${#s}-9}`;do
[[ $i == */0* ]]&&y=Nan||y=$[$i];echo $i=$y;done

通过命令行传递参数:

./combinate.sh 5 0 12


1
sed 's/ /,/g' 可以简化为 tr ' ' ',' - dreamlax
@dreamlax:好发现,谢谢!(使用tr ' ','时可以节省5个字符) - ChristopheD

4

Ruby,105 110 142 114 个字符

o=%w{+ - * /};[*ARGV.permutation].product(o.product o).map{|x,y|e=x.zip(y)*"";p"#{e}=#{eval(e)rescue:N}"}

使用方法

ruby prog.rb 1 2 3

解释

# o = ["+", "-", "*", "/"]
o=%w{+ - * /};
# ARGV = array of numbers. Generate all permutations, and apply splat operator
[*ARGV.permutation]
# Generate cartesian product of all permuted numbers and operators 
# There will be 16 operator permutations, and 6 number permutations giving a 
# total of 96 elements
.product(o.product o)
# For each of the 96 pairs, merge the operators and numbers into 1 array.
# ex - [1,2,3].zip(["+", "-"]) gives [[1, '+'], [2, '-'], [3, nil]]
# then convert the array to string by multiplying with "" => "1+2-3"
.each{|x,y|e=x.zip(y)*"";
# print output and eval result. On exception return infinity - ∞
p"#{e}=#{eval(e)rescue:N}"}

输出

1+2+3=6
1+2-3=0
1+2*3=7
1+2/3=1
1-2+3=2
1-2-3=-4
1-2*3=-5
1-2/3=1
1*2+3=5
1*2-3=-1
1*2*3=6
1*2/3=0
1/2+3=3
1/2-3=-3
1/2*3=0
1/2/3=0
1+3+2=6
1+3-2=2
1+3*2=7
1+3/2=2
1-3+2=0
1-3-2=-4
1-3*2=-5
1-3/2=0
1*3+2=5
1*3-2=1
1*3*2=6
1*3/2=1
1/3+2=2
1/3-2=-2
1/3*2=0
1/3/2=0
2+1+3=6
2+1-3=0
2+1*3=5
2+1/3=2
2-1+3=4
2-1-3=-2
2-1*3=-1
2-1/3=2
2*1+3=5
2*1-3=-1
2*1*3=6
2*1/3=0
2/1+3=5
2/1-3=-1
2/1*3=6
2/1/3=0
2+3+1=6
2+3-1=4
2+3*1=5
2+3/1=5
2-3+1=0
2-3-1=-2
2-3*1=-1
2-3/1=-1
2*3+1=7
2*3-1=5
2*3*1=6
2*3/1=6
2/3+1=1
2/3-1=-1
2/3*1=0
2/3/1=0
3+1+2=6
3+1-2=2
3+1*2=5
3+1/2=3
3-1+2=4
3-1-2=0
3-1*2=1
3-1/2=3
3*1+2=5
3*1-2=1
3*1*2=6
3*1/2=1
3/1+2=5
3/1-2=1
3/1*2=6
3/1/2=1
3+2+1=6
3+2-1=4
3+2*1=5
3+2/1=5
3-2+1=2
3-2-1=0
3-2*1=1
3-2/1=1
3*2+1=7
3*2-1=5
3*2*1=6
3*2/1=6
3/2+1=2
3/2-1=0
3/2*1=1
3/2/1=1

4

Haskell,221个字符

哎呀!!导入占用了50个字符。

import Data.List
import System
import Text.Printf
o=zip[(+),(-),(*),(/)]"+-*/"
main=do v<-getArgs;sequence[printf"%.0g%c(%.0g%c%.0g)=%.0g\n"x h y i z$f x$g y z|(f,h)<-o,(g,i)<-o,[x,y,z]<-permutations(map read v::[Float])]

getArgs需要System,printf需要Text.Printf,permutations需要Data.List,需要[[Float]]是因为/需要Fractional的实例。我们不能使用div,因为当除以零时会抛出异常。

基本上,这只是在所有可能的运算符组合和输入参数的排列中进行迭代,并打印结果。

这三个%.0g可以被%g替换,以减少6个字符,但结果将看起来很丑,例如1.0/(2.0*3.0)=0


~$ ./a.out 0 4 9
0+(4+9)=13
4+(0+9)=13
9+(4+0)=13
4+(9+0)=13
9+(0+4)=13
0+(9+4)=13
0+(4-9)=-5
4+(0-9)=-5
9+(4-0)=13
4+(9-0)=13
9+(0-4)=5
0+(9-4)=5
0+(4*9)=36
4+(0*9)=4
9+(4*0)=9
4+(9*0)=4
9+(0*4)=9
0+(9*4)=36
0+(4/9)=0
4+(0/9)=4
9+(4/0)=Infinity
4+(9/0)=Infinity
9+(0/4)=9
0+(9/4)=2
0-(4+9)=-13
4-(0+9)=-5
9-(4+0)=5
4-(9+0)=-5
9-(0+4)=5
0-(9+4)=-13
0-(4-9)=5
4-(0-9)=13
9-(4-0)=5
4-(9-0)=-5
9-(0-4)=13
0-(9-4)=-5
0-(4*9)=-36
4-(0*9)=4
9-(4*0)=9
4-(9*0)=4
9-(0*4)=9
0-(9*4)=-36
0-(4/9)=-0
4-(0/9)=4
9-(4/0)=-Infinity
4-(9/0)=-Infinity
9-(0/4)=9
0-(9/4)=-2
0*(4+9)=0
4*(0+9)=36
9*(4+0)=36
4*(9+0)=36
9*(0+4)=36
0*(9+4)=0
0*(4-9)=-0
4*(0-9)=-36
9*(4-0)=36
4*(9-0)=36
9*(0-4)=-36
0*(9-4)=0
0*(4*9)=0
4*(0*9)=0
9*(4*0)=0
4*(9*0)=0
9*(0*4)=0
0*(9*4)=0
0*(4/9)=0
4*(0/9)=0
9*(4/0)=Infinity
4*(9/0)=Infinity
9*(0/4)=0
0*(9/4)=0
0/(4+9)=0
4/(0+9)=0
9/(4+0)=2
4/(9+0)=0
9/(0+4)=2
0/(9+4)=0
0/(4-9)=-0
4/(0-9)=-0
9/(4-0)=2
4/(9-0)=0
9/(0-4)=-2
0/(9-4)=0
0/(4*9)=0
4/(0*9)=Infinity
9/(4*0)=Infinity
4/(9*0)=Infinity
9/(0*4)=Infinity
0/(9*4)=0
0/(4/9)=0
4/(0/9)=Infinity
9/(4/0)=0
4/(9/0)=0
9/(0/4)=Infinity
0/(9/4)=0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接