Program_Worker's profileMicrosoft Beta HomePhotosBlogLists Tools Help

Blog


    November 22

    Google面试第一题解答

    题目:解答下面的隐藏等式,其中的M和E的值可以互换,但不允许第一位是0。
    WWWDOT - GOOGLE = DOTCOM

    解答代码:
    /*******************************/
    /*   Q:WWWDOT-GOOGLE=DOTCOM  */
    /*   A:777589-188103=589486          */
    /*     777589-188106=589483           */
    /*******************************/


    #include <stdio.h>


    void getans(int num[], int n_tmp)    //通过递归调用对num_0_9数组进行组合排序
    {
      
    int tmp;
      
    int w,d,o,t,g,l,e,c,m,wwwdot,google,dotcom;
      if(
    n_tmp == 1){
        
    w = num[0];
        
    d = num[1];
        
    o = num[2];
        
    t = num[3];
        
    g = num[4];
        
    l = num[5];
        
    e = num[6];
        
    c = num[7];
        
    m = num[8];
        
    wwwdot = w*111000 + d*100 + o*10 + t;
        
    google = g*100100 + o*11000 + l*10 + e;
        
    dotcom = d*100000 + o*10010 + t*1000 + c*100 + m;

        
    //其中的M和E的值可以互换,但不允许第一位是0。
        
    if(w!=0 && g!=0 && d!=0)    
            if((
    wwwdot - google == dotcom) || (wwwdot - (google - e + m) == (dotcom - m + e)))
                
    printf("%d - %d = %d\n",wwwdot,google,dotcom);
      }
      else{
        for(
    int i = 0; i < n_tmp; i++){
          
    tmp=num[i]; num[i]=num[n_tmp-1]; num[n_tmp-1]=tmp;
          
    getans(num, n_tmp-1);
          
    tmp=num[i]; num[i]=num[n_tmp-1]; num[n_tmp-1]=tmp;

        }
      }
    }

    void main()
    {
      
    int n = 10;
      
    int num_0_9[]={0,1,2,3,4,5,6,7,8,9};

      
    getans(num_0_9, n);

    }

    Comments (10)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    Nov. 2
    No namewrote:
    Warcraft game like this to (World of Warcraft gold) and (wow gold)! Price concessions, credibility is also good!
    Sept. 18
    No namewrote:
    Welcome to enter (wow gold) and (wow power leveling) trading site, (Rolex) are cheap, (World of Warcraft gold) credibility Very good! Quickly into the next single! Key words directly to the website click on transactions! -262336526573703
    Aug. 21
    sky fuwrote:
    太有才了!不是不会解,而是不会像你一样提问题!高!
    Apr. 1
    luyangwrote:
       888644 -244297= 644347
    Jan. 30
    Xiuliwrote:
    哦,手算出来的
    Oct. 13
    97风wrote:
    c语言我是白学了
    看得头晕
    Mar. 17
    Picture of Anonymous
    ╋Claude╋ wrote:
    自愧不如....以后电脑不懂的就请教你啊=D

    各位朋友,为方便官员管理,请去分会注册个会员号,1到999随便选
    请各位合作,为你我提供便捷,也为以后活动安排打好基础
    谢谢啦
    Jan. 19
    Picture of Anonymous
    ≈Darkness≈ wrote:
    带着电脑面试?现场设计?。。
    Nov. 30
    Picture of Anonymous
    漫卷轻舒 wrote:
    呵呵
    Nov. 25

    Trackbacks (5)

    The trackback URL for this entry is:
    http://codesky.spaces.live.com/blog/cns!63B6C0D8329C941B!887.trak
    Weblogs that reference this entry