<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 1,  comments - 0,  trackbacks - 0
    金山訓練營入學考試題
    1 編寫函數實現十進制正整數到十四進制數的轉換,在屏幕輸出轉換結果。
    說  明:用0, 1, 2, 3,....., 8, 9, A, B, C, D表示十四進制的基本的14個數。
            例:鍵盤輸入14,屏幕輸出10。


    比較好的解法:
    void fun( int input)
    {
        if (input >= 14)
            fun(input/14);
        printf("%c","0123456789ABCD"[input%14]);
    }

    很明顯考的不用庫函數,其他實現這里就不貼了
    3 文件名:3.cpp
    功  能:編程實現猜詞游戲
    說  明:對于單詞“hello”,程序提示輸出:?????,等待用戶輸入。
    用戶輸入時,若單詞包含該字母,如“l”,則程序顯示輸出“??ll?”;
    若單詞不含該字母,如“a”,則程序提示用戶猜錯。
    繼續等待用戶輸入,直到用戶猜出全部字母,或輸入錯誤次數超過最大允許出錯次數,游戲結束。
    條  件:1)      單詞由程序內定,由全小寫字母組成
    2)      提示輸出問號數量等于單詞長度
    3)      最大允許出錯次數等于單詞長度
    看我的實現
    int main()
    {
    string str="hello",temp="?????",ss;
    int num=0;
    while (temp.find_first_of('?')!=-1&&num<str.size())
    {
        cin
    >>ss;
        
    ++num;
        
    for (int i=0;i<ss.size();++i)
        
    {
            
    for (int j=0;j<str.size();++j)
            
    {
                
    if (ss.at(i)==str.at(j))
                
    {
                    temp.at(j)
    =str.at(j);
                }

            }

        }

    cout
    <<temp<<endl;
    }

        
    return 0;
    }
    topic.csdn.net\u\20080517\21\8606a5d6-9c07-4ebc-a7bb-243af402e20b4bc0.html

    【某公司C++筆試題】

    1.編寫函數,檢查給定字符串是否整數,如果是,返回其整數值(注:不允許使用某種特定的庫函數)。
    也算經典的atoi問題了吧,看我的實現
    int my_atoi(char* str)
    {
        
    int i=0,num=0;
        
    while (*str)
        
    {
            
    if (*str<='9'&&*str>='0')
            
    {
                num
    =num*10;
                num
    +=(*str-'0');
            }

            
    else
            
    {
                cout
    <<"ileigg word\n";
                
    return -1;
            }

            str
    ++;
        }


        
    return num;
    }
    上課的時候我曾用java寫過一個類似的,當時用的兩層循環來計算,后來看了一個帖子,很慚愧。
    看下面淘寶網一道面試題
    讓我寫出atol的實現代碼,我記得微軟的源碼,當場寫出來了,如下: 
    long __cdecl atol( 
            
    const char *nptr 
            ) 

            
    int c;              /* current char */ 
            
    long total;        /* current total */ 
            
    int sign;          /* if '-', then negative, otherwise positive */ 

            
    /* skip whitespace */ 
            
    while ( isspace((int)(unsigned char)*nptr) ) 
                
    ++nptr; 

            c 
    = (int)(unsigned char)*nptr++;        sign = c;          /* save sign indication */ 
            
    if (c == '-' || c == '+'
                c 
    = (int)(unsigned char)*nptr++;    /* skip sign */ 

            total 
    = 0

            
    while (isdigit(c)) 
                total 
    = 10 * total + (c - '0');    /* accumulate digit */ 
                c 
    = (int)(unsigned char)*nptr++;    /* get next char */ 
            }
     

            
    if (sign == '-'
                
    return -total; 
            
    else 
                
    return total;  /* return result, negated if necessary */ 
    }
     

    接著面試官問我,為什么要在程序中做(
    int)(unsigned char)*nptr的強轉?我沒答出來,哪位能說說為什么要強轉啊????

    看正解:
    因為isspace(),isdigit()這類函數接受一個int 參數,參數的值必須是一個可以用unsigned char 表示的值或者是EOF,以下是 man 手冊的原文: 

    int isspace(int c); 
    int isdigit(int c); 
     
    These functions check whether c, which must have the value of anunsigned 
    char or EOF,falls into a cetern charcter class according to the current locale. 

    所以需要用c 
    = (int)(unsigned char)*nptr++,來確保從 *nptr++ 到 c 是進行零擴展而不是符號擴展,保證 c 中存放的是一個unsigned char 所能表示的值。 

    還有一類題是經典的itoa,下面給出正解:
    void my_itoa(int s, char str[]) {
        
    int
     i, t;
        
    for (i = 0, t = s; t > 0;) 
    {
            str[i
    ++= t / 10 + '0'
    ;
            t 
    %= 10
    ;
        }

    }




    2.有兩個無序鏈表lsit1和list2,編寫函數把list1和list2合并成一個遞增的鏈表。
    這道題考的是基礎知識,學過數據結構都應該能寫出來

    struct Node 
    {
        
    int value;
        Node
    * next;
    }
    ;
    void creat_list(Node*& head)
    {
        
    int num=0;

        
    while (1)
        
    {
                cin
    >>num;
            
    if (num==-1)
            
    {
                
    break;
            }

            Node
    * p=new Node;
            p
    ->value=num;
            p
    ->next=head->next;
            head
    ->next=p;
        }

    }

    void print_all(Node* head)
    {
        Node
    * q=head->next;
        
    while(q)
        
    {
        cout
    <<q->value<<' ';
        q
    =q->next;
        }

    cout
    <<endl;
    }

    void list_sort(Node* head)
    {
        Node
    * p=head,*q=NULL;
        
    while(1)
        
    {
            p
    =head;
            
    for(;p->next!=q;p=p->next)
            
    {
                
    if (p->value>p->next->value)
                
    {
                    
    int temp=p->value;
                    p
    ->value=p->next->value;
                    p
    ->next->value=temp;
                }

            }

            q
    =p;
            
    if (head->next==q)
            
    {
                
    break;
            }

        }

    }

    void two_list_sort(Node* head,Node* head1,Node*& new_list)
    {
        list_sort(head);
        list_sort(head1);

        print_all(head);

        print_all(head1);

        Node
    * p=head->next;
        Node
    * p1=head1->next;
        
    while (p&&p1)
        
    {
            
    if (p->value<=p1->value)
            
    {
                Node
    * m=new Node;
                m
    ->value=p->value;
                m
    ->next=new_list->next;
                new_list
    ->next=m;
                p
    =p->next;
            }
     
            
    else
            
    {
                Node
    * m=new Node;
                m
    ->value=p1->value;
                m
    ->next=new_list->next;
                new_list
    ->next=m;
                p1
    =p1->next;
            }

        }

        
    while (p)
        
    {
            Node
    * m=new Node;
            m
    ->value=p->value;
            m
    ->next=new_list->next;
            new_list
    ->next=m;
            p
    =p->next;
        }

        
    while (p1)
        
    {
            Node
    * m=new Node;
            m
    ->value=p1->value;
            m
    ->next=new_list->next;
            new_list
    ->next=m;
            p1
    =p1->next;
        }


        list_sort(new_list);
        
    }

    int main()
    {
        Node
    * head=new Node;
        Node
    * head1=new Node;
        head
    ->next=NULL;
        head
    ->value=0;
        head1
    ->next=NULL;
        head1
    ->value=1;
        creat_list(head);
        creat_list(head1);
        print_all(head);

    print_all(head1);


    Node
    * new_list=new Node;
    new_list
    ->next=NULL;
    new_list
    ->value=0;
    two_list_sort(head,head1,new_list);
    print_all(new_list);
        
    return 0;
    }

    topic.csdn.net\u\20081011\15\9ee842e0-9c0d-4804-8376-42abdfe80698.html

    posted on 2012-06-05 09:41 憤怒的考拉 閱讀(55) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    搜索

    •  

    最新評論

    主站蜘蛛池模板: 亚洲国产高清人在线| 亚洲精品无码永久在线观看| a级毛片免费在线观看| 国产精品成人无码免费| 亚洲乱理伦片在线观看中字| 无码日韩精品一区二区免费| 亚洲午夜电影一区二区三区| 91精品国产免费久久久久久青草| 亚洲神级电影国语版| 黄页网站免费观看| 亚洲人成无码网站在线观看 | 一区二区三区免费在线观看| 中文字幕在线免费| 亚洲七七久久精品中文国产| 亚州**色毛片免费观看| 毛片免费观看网站| 亚洲国产精品精华液| 国产在线jyzzjyzz免费麻豆| 亚洲一卡2卡4卡5卡6卡残暴在线| 99久久免费国产精精品| 亚洲av伊人久久综合密臀性色 | 亚洲AV无码成人网站久久精品大| 久操视频免费观看| 亚洲午夜精品在线| 免费永久在线观看黄网站| 亚洲免费中文字幕| 国产免费观看a大片的网站| 亚洲免费日韩无码系列| 亚洲永久永久永久永久永久精品| 色婷婷7777免费视频在线观看 | 亚洲人成黄网在线观看| 日本高清免费不卡在线| 国产免费AV片在线观看播放| 亚洲理论片在线中文字幕| 麻豆成人精品国产免费| 一级做受视频免费是看美女| 亚洲精品在线不卡| 亚洲阿v天堂在线2017免费| 最好看最新的中文字幕免费| 风间由美在线亚洲一区| 免费看少妇作爱视频|