比如 int a,b,c;如果a==b,c就是0,如果a!=b,c就是1

解决方案 »

  1.   

    直接写不就行了?
    if(a==b)
    {
       c=0;
    }
    else
    {
       c=1;
    }
      

  2.   

    int a=1,b=2,c;
    if(a == b)
    {
    c = 0;
    }
    else
    {
    c = 1;
    }
      

  3.   


    int c = a==b?0:1;简单吧。
      

  4.   

     弄个怪的.
     c = (a-b) % (a -b- 1); 
      

  5.   

    c=Convert.ToInt32(!(a==b)); 
      

  6.   

    可以么?a=6,b=5,就爆了。- -         int a = 5, b = 5;
            int c;
            c = Convert.ToInt32(!(a == b)); 
            Response.Write(c);
      

  7.   

    c = Convert.ToInt32( (a ^ b) > 0);
      

  8.   

    或者这样: c = Convert.ToInt32(!((a ^ b) == 0));
    保险一些
      

  9.   

    为何不用位运算
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;namespace CSharpTest
    {
          class Program
        {        
            static void Main(string[] args)
            {
                int a = 3, b = 4;
                Console.WriteLine((a^b) > 1?1:0);
              
            }        
        }
    }
      

  10.   

    果然是变态题目
    好好的if else 或者 ?:不用
      

  11.   

    第一感觉是用异或操作 xor
      

  12.   

    c = a==b ? 0 : 1
      

  13.   

    c=Convert.ToInt32(!(a==b));可能这个
      

  14.   

    xue xi le ,dan bu zhi dao xue shen me
      

  15.   

    int c = (a==b?0:1);
      

  16.   

    public static String trimToNull(String value)
        {
            String result = null;
            if (value != null)
            {
                result = value.trim();
                if ("".equals(result))
                {
                    result = null;
                }
            }
            return result;
        }
      

  17.   

    /*
         * Overriding equals()
         * */
        public boolean equals(Object obj)
        {
            if(obj instanceof BigNumber)
            {
                BigNumber temp = (BigNumber)obj;
                try {
                    temp = this.sub(temp);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if("0".equals(temp.toString()))
                {
                    return true;
                }
                else
                {
                    return false;
                }            
            }
            else if(obj instanceof String)
            {
                BigNumber temp = new BigNumber((String)obj);
                try {
                    temp = this.sub(temp);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                if("0".equals(temp.toString()))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }    
        }
      

  18.   

    /*
         * Override toString()
         * */    
        public String toString()
        {
            StringBuffer sbf = new StringBuffer("");
            if(this.length == 1)
            {
                return "" + this.bn[0];
            }
            else
            {
                int k = 0;
                while(k < this.length && this.bn[k] == 0)
                {
                    k++;
                }
                for(int i=k; i<length; i++)
                {
                    //StringBuffer sb = new StringBuffer(Integer.toString(bn[i]));
                    sbf.append(bn[i]);
                }
                if(null==sbf || "".equals(sbf.toString()))
                {
                    sbf.append("0");
                }
                
                return sbf.toString();
            }
        }
      

  19.   

    /*
     * 除法取余和取整
     */
    private ArrayList divider(BigNumber b)throws Exception
    {
    ArrayList arr = new ArrayList();
    BigNumber rslt = null;//商
    BigNumber bn = new BigNumber(this.length); //被除数

            //a的长度小于b的长度时,商为0
            if(this.length < b.length) {
                rslt = new BigNumber(1);
                rslt.bn[0] = 0;  
            }
            //a的长度等于b的长度时,将a的长度加1再除以b
            else if(this.length==b.length){
                BigNumber a1 = new BigNumber(this.length+1);
                for(int i=a1.length-1;i>0;i--){
                    a1.bn[i] = this.bn[i-1];
                }
                a1.bn[0] = 0;
                rslt = new BigNumber(1);
                rslt.bn[0] = a1.divide(b).bn[1];
        /*a的长度大于b的长度时,采用如下方法:
        //从a的高位起取b.length+1位,循环减b,循环结束条件为取出来的a的最高位a[r]小于等于0且次高位小于b的最高位b[0],
        */
            }else{
                rslt = new BigNumber(this.length-b.length+1);    //商
                
                for(int i=0;i<length;i++)  bn.bn[i] = this.bn[i];
                for(int i=0;i<rslt.length;i++)    rslt.bn[i] = 0;            
                
                for(int r=0;r<rslt.length-1;r++){
                    int count = 0;                
                    while(bn.bn[r]>0||(bn.bn[r]==0&&bn.bn[r+1]>=b.bn[0])){
                        for(int i=b.length+r,j=b.length-1;j>=0&&i>0;i--,j--){
                            if(bn.bn[i]>=b.bn[j]) {
                                bn.bn[i] -= b.bn[j];
                            }else{
                                bn.bn[i-1] -=1;            
                                bn.bn[i] -= b.bn[j]-10;            
                            }
                        }
                        count++;
                    }
                    
                    if(bn.bn[r] < 0){
                        for(int i=b.length+r,j=b.length-1;j>=0;i--,j--){
                            if((bn.bn[i] += b.bn[j])>=10) {
                                bn.bn[i-1] +=1;
                                bn.bn[i] -= 10;
                            }
                        }
                        count--;
                    }
                    //System.out.println(count);
                    rslt.bn[r] += count/10;
                    rslt.bn[r+1] = (short)(count%10);
                }
            }
            arr.add(0, rslt);
            arr.add(1, bn);
            
    return arr;
    }
      

  20.   

    /*
     * 除法
     * */
    public BigNumber divide(BigNumber b)throws Exception{

    return (BigNumber)this.divider(b).get(QUOTIENT);
    }

    /*
     * 取余
     * */
    public BigNumber mod(Object o)
    {
    String str = "";
    BigNumber c = null;
    BigNumber remainder = null;
    if(o instanceof String)
    {
        str = (String)o;
        

    //校验是否都为数字
    boolean numberFlag = Pattern.matches("[\\d]+",str);
    if(numberFlag)
    {
    c = new BigNumber(str);
    }
    else
    {
    throw new NumberFormatException("There are some charactor aren't number!");
    }

    //调用moder()取余
    try
    {
    remainder = this.moder(c);
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    e.printStackTrace();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    else if(o instanceof BigNumber)
    {
    c = (BigNumber)o;

    try
    {
    remainder = this.moder(c);
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    e.printStackTrace();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }
    else
    {
    throw new NumberFormatException("The number format is wrong !");
    }


    return remainder;
    }

    /*
     * 取余
     */
    private BigNumber moder(BigNumber b)throws Exception
    {
    return (BigNumber)this.divider(b).get(REMAINDER);
        }
      

  21.   

    /*
     * 加法
     * */
    public BigNumber plus(BigNumber b)throws Exception{
    BigNumber rslt = new BigNumber(Math.max(this.length,b.length)+1);
    for(int i=0;i<rslt.length-this.length;i++){
    rslt.bn[i] = 0;
    }
    for(int i=rslt.length-1;i>=rslt.length-this.length;i--){
    rslt.bn[i] = this.bn[i-rslt.length+this.length];
    }

    int k=0;
    while(b.bn[k]==0&&k++<b.length){}
    if(b.bn[k] < 0){//加负数
    b.bn[k] *= -1;
    rslt = this.sub(b);
    }else{
    // 加法核心代码 
    for(int i=rslt.length-1,j=b.length-1;j>=0;i--,j--){
    if((rslt.bn[i] += b.bn[j])>=10) {
    rslt.bn[i-1] +=1;
    rslt.bn[i] -= 10;
    }
    }
    //
    }
    return rslt;
    }

    /*
     * 大数与正整数的乘积,将整数转换成大数再做乘积
     * */
    public BigNumber multiply(long num)throws Exception{//大数与正整数的乘积,将整数转换成大数再做乘积
    int n = 1;
    long  num1 = num;
    while((num1 /= 10)>0){
    n++;
    }
    BigNumber bgnm = new BigNumber(n);
    BigNumber rslt = new BigNumber(this.length+n);

    bgnm.bn[n-1] = (short)(num%10);
    for(int i=n-2;i>=0;i--){
      bgnm.bn[i] = (short)((num /= 10)%10);

    rslt = this.multiply(bgnm);
    return rslt;
    }

    /*
     * 乘法 大数乘大数
     * */
    public BigNumber multiply(BigNumber b) throws Exception{
    BigNumber rslt = new BigNumber(this.length+b.length);
    for(int i=0;i<rslt.length;i++){rslt.bn[i] = 0;}

    //乘法计算思路:两个数组的各个元素相乘a[i]*b[j],
    //乘积保存到rslt数组对应的元素位置上rslt[i+j+1],
    //然后向rslt[i+j]进位,最后将rslt[i+j+1]的值取对10的余数
    for(int j=b.length-1;j>=0;j--){
    for(int i=this.length-1;i>=0;i--){ 

    rslt.bn[i+j+1] += this.bn[i]*b.bn[j];
    rslt.bn[i+j] += rslt.bn[i+j+1]/10;
    rslt.bn[i+j+1] = (short)(rslt.bn[i+j+1]%10);
    }
    }

    return rslt;
    }
      

  22.   

    private short[] bn = null;

    private int length = 3;
    private static final int QUOTIENT = 0;//商
    private static final int REMAINDER = 1;//余数
    //public static void test(){System.out.println("Hello!");}
    //BigNumber a =null;
    public BigNumber(){}

    public BigNumber(int l){//构造函数
    length = l;
    bn = new short[length];
    for(int i=0;i<length;i++){
    bn[i] = random();
    }
    while(bn[0]==0) bn[0] = random();
    }

    /*
     * 构造方法,手动输入
     * */
    public BigNumber (String s)
    {
    length = s.length();

    bn = new short[length];

    for(int i=0 ;i<length;i++)
    {
    bn[i] = (short)Integer.parseInt(""+s.charAt(i));
    }
    }

    public short random(){//获得随机数0-9
    short a = (short)(10*Math.random());
    if(a<=9) return a;
    else return 0;
    }

    /*
     *复制,把a的值赋给b
     * */
    private static void copy (BigNumber a,BigNumber b)
    {
    for(int i=0;i<b.length-a.length;i++)
    {
    b.bn[i] = 0;
    }
    System.arraycopy(a.bn, 0, b.bn, b.length-a.length, a.length);
    }

    /*
     * 减法
     * */
    public BigNumber sub(BigNumber b)throws Exception{
    if("0".equals(b.toString()))
    {
    return this;
    }
    BigNumber rslt = new BigNumber(Math.max(this.length, b.length)+1);
    int r = 0,y = 0;
    while(this.bn[r]==0&&r++<this.length){}
    while(b.bn[y]==0&&y++<b.length){}
    if(this.length-r<b.length-y){
    rslt = b.sub(this);
    int i = 0;
    while(rslt.bn[i++]==0&&i<rslt.length){}
    rslt.bn[--i] *= -1;
    }else{
    for(int i=0;i<rslt.length;i++){
    rslt.bn[i] = 0;
    }
    for(int i=rslt.length-1;i>=rslt.length-this.length;i--){
    rslt.bn[i] = this.bn[i-rslt.length+this.length];
    }
                //减法核心
    int i1=rslt.length-1;
    int j1=b.length-1;
    for(;j1 >= 0;i1--,j1--)
    {
    if(rslt.bn[i1]>=b.bn[j1]) {
    rslt.bn[i1] -= b.bn[j1];
    }else{
    rslt.bn[i1-1] -=1;
    rslt.bn[i1] -= b.bn[j1]-10;
    }
    }
                //循环到最后一步,如果被减数前一位为0,且被借1,则需继续向高位借1
    i1++;
    while(i1>1 && rslt.bn[i1-1]==-1)
    {
    i1--;
    rslt.bn[i1-1] -=1;
    rslt.bn[i1] +=10;
    } if(rslt.bn[0]<0) {
    rslt = b.sub(this);
    int i = 0;
    while(rslt.bn[i++]==0&&i<rslt.length){}
    rslt.bn[--i] *= -1;
    }
    }

    return rslt;
    }
      

  23.   

    直接写int a = 1, b = 2;
    int c = 1;
      

  24.   

    C# codeusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.IO;namespace CSharpTest 
    {class Program 
        {staticvoid Main(string[] args) 
            {int a=3, b=4; 
                Console.WriteLine((a^b)>1?1:0); 
              
            }         
        } 

      

  25.   

    写个 if  else不就可以判断了吗
    呵呵
    不过学习的精神很值得学习啦
      

  26.   

    (a-b)/(a+b),只要a=b,则就是0,反之就是1了,另外就是不知道是否要考虑负数的问题。
      

  27.   

    c = ((a^b) == 0)c = ((a&b) == a && (a&b) == b)
      

  28.   


    雷!你这个要后面的/(a+b)干吗,你不就是只要判断a-b=0么,你不就是判断a=b么真费劲还考虑负数,你都考虑多了,不要/(a+b)或者,你干脆用*(a+b)……兄台你是受害者
      

  29.   

    int c = Math.Abs(Math.Sign(a - b));
       
      

  30.   

    if(a%b==0)
    {
       c=0;
    }
    else
    {
       c=1;
    }