• 2015年趋势科技笔试A卷


    题目原题来源:http://wenku.baidu.com/link?url=BHz9dr7Dbql5Ai0fTaUsi8QH-ieA9UAtw8kpf-Us_cGUnsz7ZIU1SfHIp33Cphcp0n6uPikWL6r8n0a0zQ0wNOMLGnXwxMd2uSHqv8-WJIe

    35题:C

    #include<iostream>
    #include<vector>
    #include<string>
    #include<algorithm>
     
    std::string foo(const std::string& s) {
        std::string ret;
        ret.reserve(s.size());
        for(size_ti=0;i<s.size();++i) {
            ret.push_back(s[i]|0x20);
        }
        return ret;
    }
    bool compare_string(const std::string& lhs,const std::string &rhs) {
        returnfoo(lhs)<foo(rhs);
    }
    int main(int argc,constchar* argv[])
    {
        constchar* data[]={"Have","fun","in","Trendmicro"};
        std::vector<std::string>vec(data,data+sizeof(data)/sizeof(data[0]));
        std::sort(vec.begin(),vec.end(),compare_string);
        std::copy(vec.begin(),vec.end(),std::ostream_iterator<std::string>(std::cout," "));
        std::cout<<std::endl;
        return 0;
    }
    34:BDE(下面是改动后的代码)

    #include<stdio.h>
    #include<exception>
    #include<stdlib.h>
     
    template<unsigned int size>
    class CTestObj
        {
        private:
            int *m_pvalue;
        public:
            CTestObj(int arr[size])
                {
                m_pvalue=new int;
                *m_pvalue=0;
                for(unsigned int i=0;i<size;i++)
                    {
                    *m_pvalue+=arr[i];
                    }
                }
            ~CTestObj()
                {
                delete m_pvalue;
                }
            voidTest()
                {
                if(*m_pvalue>100)
                    {
                    throw std::exception();
                    }
                }
        };
     
    int main(int argc,const char* argv[])
    {
        try
            {
            int arr[]={1,2,3,4,500};
            CTestObj<_countof(arr)> *pobj =new CTestObj<_countof(arr)>(arr);
            pobj->Test();
            delete pobj;
            }
        catch(std::exception)
            {
            printf("exception
    ");
      //    delete pobj;
            }
        printf("end
    ");
        return 0;
    }
    9:A(供參考)

    #include<stdio.h>
    #include<iostream>
    usingnamespace std;
     
    #define BUFFER_SIZE 12
    /*void Copydata(const char *imgdata,int width,int height)
    {
        charbuf[BUFFER_SIZE];
       if(width*height>BUFFER_SIZE) return;
        const char*p=imgdata;
        for(inti=0;i<width;++i){
            for(intj=0;j<height;++j){
               buf[i*width+j]=*p++;
            }
        }
       cout<<buf<<endl;
    }
    void Copydata(const char *data,int len)
    {
       if(len>BUFFER_SIZE) return;
        charbuf[BUFFER_SIZE];
       memcpy(buf,data,len);
       cout<<buf<<endl;
    }*/
    void Copydata(const char *imgdata,int width,int height)
    {
        char *buf=(char *)malloc(width*height);
        if(NULL==buf)return;
        memcpy(buf,imgdata,width*height);
        cout<<buf<<endl;
        free(buf);
    }
    int main(int argc,const char* argv[])
    {
        char *p="abcdefghijkl";
        Copydata(p,3,4);
        return 0;
    }
    8:BC

    #include<stdio.h>
    #include<iostream>
    usingnamespace std;
     
    int main(int argc,constchar* argv[])
    {
        intarr[3][3]={{1,2,3},{4,5,6},{7,8,9}};
        inti=1,j=2;
        cout<<**(arr+3*i+j)<<endl;
        cout<<*(*(arr+i)+j)<<endl;
        cout<<*(arr[i]+j)<<endl;
        cout<<*(arr+3*i+j)<<endl;
        return 0;
    }

    7:A

    #include<stdio.h>
    #include<iostream>
    using namespace std;
    void check()
    {
        unsigned int i=1;
    //    char *cptr =(char *)i;
        char *cptr= (char *)&i;
    //    char*cptr=&(char *)i;
    //    char cptr =(char)&i;
        if(*cptr!=0)
            printf("1");
        else
            printf("0");
    }
    int main(int argc,const char* argv[])
    {
        check();
        return 0;
    }

    6:BC

    #include <stdio.h>
    #include <iostream>
    using namespace std;
    void f(char *s,char *t)
    {
        do{
            *s++=*t++;
        }while(*t!='');
    	*s='';
    //    cout<<s<<endl;
    }
    void f(char *s,char *t)
    {
        while(*t){
            *s++=*t++;
        }
        *s='';
       cout<<s<<endl;
    }   
    void f(char *s,char *t)
    {
        do
        {
            *s=*t;
            s++;
        }while(*t++);
    //   cout<<s<<endl;
    }
    void f(char *s,char *t)
    {
        unsigned i;
        for(i=0;i<strlen(t);i++)
            s[i]=t[i];
        s[i]='';
    }
    int main(int argc,const char* argv[])
    {
        char *t="abcde";
        char *s=(char *)malloc(10);
        f(s,t);
    	cout<<s<<endl;
        return 0;
    }
     

    4:D

    //假设基类对象指向子类对象的话 ,而且此函数是虚函数的时候。基类对象调用子类中定义的此函数。
    #include<stdio.h>
    #include<iostream>
    usingnamespace std;
     
    class Base{
        int x;
    public:
        Base(){x=1;}
        virtualvoid display(){
            cout<<x;
        }
        void show(){
            cout<<x;
        }
    };
    class Derived:public Base{
        int y;
    public:
        Derived(){y=2;}
        voiddisplay() {
            cout<<y;
        }
        void show(){
            cout<<y;
        }
    };
    int main()
    {
        Base b;
        Derived d;
        b.display();
        d.display();
        Base *p=&d;
        p->display();
        b.show();
        d.show();
        p->show();
        return 0;
    }


     

  • 相关阅读:
    客户端和Web Api服务的交互
    ASP.NET MVC4 validate验证遇到DateTime 类型的Bug(完整解决方案)
    不能说的秘密 一个很感人的爱情故事
    快五一了,申请了第一个Blog,哈哈。
    人生没有目标是可怕的。。。
    在.NET中使用SMTP发送邮件,有一些疑问
    smtp验证发邮件,今天好郁闷,终于解决了
    C#、.NET迷你音乐播放器(改进版)
    C#实现冒泡排序 堆栈 队列
    C#、.NET版邮件(群)发系统
  • 原文地址:https://www.cnblogs.com/llguanli/p/6962476.html
Copyright © 2020-2023  润新知