中软国际笔试题汇总

来源:互联网 发布:易观数据造假 编辑:程序博客网 时间:2024/04/27 20:42
#include<stdio.h> 
//#include<string.h>


/*void fun(const char * str, int len)
{
int i = 0;
int j = len - 1;
while (i < j)
{
if(str[i]==str[j])
{
i++;
j--;
}
else
{
printf("NO\n");
return;
}
}
printf("YES\n");
return;
}
int strcmp(const char *src,const char *dst) 

    int i = 0; 
    while(src[i] && dst[i]) 
        { 
        if(src[i] > dst[i]) 
            return 1; 
            else 
                if(src[i] < dst[i]) 
                    return -1; 
                    else 
                        i++;
if(src[i] == '\0' && dst[i] != '\0')
return -1;
else if (src[i] != '\0' && dst[i] == '\0')
{
return 1;
}
    } 
    return 0; 
}  */


int add(int * arr,int n)
{
/*int i;
int num = 0;
for(i=0;i<n;i++)
{
num += arr[i];
}
return num;
*/
static int num = 0;
if(n-->0)
{
num += arr[n];
add(arr,n);
}
return num;
}
 
int main(int argc,char *argv[]) 

/*unsigned short a = 0x5;
unsigned int sum = 0;
while (a)
{
int i = 0;
int tmp = 1;
while (i++<4)
{
sum += (a&0x1)*tmp;
tmp *=10;
a = a>>1;
}
}
printf("%d\n",sum);
return 0;
char * str1 = "asdffdsa";
char * str2 = "asdfsa";
fun(str1,strlen(str1));
fun(str2,strlen(str2));
return 0;
char *str1 = "abd"; 
    char *str2 = "abd"; 
    printf("%d\n",strcmp(str2,str1)); 
    return 0; */


int arr[] = {1,2,3,4,5,6};
printf("%d\n",add(arr,5));


1、 Windows 下消息处理机制流程?sendmessagepostmessage的区别。

http://blog.csdn.net/npjocj/article/details/6611029

2、 不用库函数,实现Strcpy函数。

char * strcpy(char * strDest,const char * strSrc)        {                if ((strDest==NULL)||strSrc==NULL))                                        return NULL;                    char * strDestCopy=strDest;                 while ((*strDest++=*strSrc++)!='\0');                 return strDestCopy;        }
3 设计双链表数据结构类:实现增加,浏览,删除,头删,尾删,头插,尾插;头删,尾删,头插,尾插需要考虑时间复杂度。

#include <iostream>
using namespace std;
template<class T>
class list;
template <class T>
class node
{
friend class  list<T>;
node(){}
node(T _date)
{
date=_date;
next=NULL;
front=NULL;
}
private:
T date;
node<T>* next;
node<T>* front;
};
template <class T>
class list
{
public:
class iterator
{
public:
iterator(){}
iterator(node<T>*& _p)
{
p=_p;
}
iterator operator =(iterator it)
{
this->p = it.p;
return (*this);
}
bool operator ==(const iterator & it)
{
return (this->p == it.p);
}
bool operator !=(const iterator & it)
{
return (this->p != it.p);
}
T operator *()
{
return (p->date);
}
iterator operator ++(int i)
{
this->p = this->p->next;
return (*this);
}
private:
node<T>* p;
};


list()
{
len=0;
head=new node<T>();
head->next = NULL;
head->front = NULL;
}
iterator push_front(T _date)
{
curr = new node<T>(_date);
if(head->next == NULL)
{
head->next = curr;
curr->front = head;
}
curr->next = head->next;
head->next->front = curr;
head->next = curr;
curr->front = head;
len++;
return iterator(curr);
}
iterator push_back(T _date)

curr = head;
while(curr->next != NULL)
{
curr = curr->next;
}
curr->next = new node<T>(_date);
curr->next->front = curr;
len++;
return iterator(curr->next);
}
iterator begin()
{
return iterator(head->next);
}
iterator end()
{
curr = head;
while(curr->next!=NULL)
{
curr = curr->next;
}
return iterator(curr->next);
}
iterator find(const T & _date)
{
curr = head;
while(curr->date == _date)
{
curr = curr->next;
}
return iterator(curr);
}
T back()
{
curr = head;
while(curr->next!=NULL)
{
curr = curr->next;
}
return curr->p->date;
}
T front()
{
return head->next->date;
}
void clear()
{
delete head;
head = NULL;
}
int size()
{
return len;
}
iterator erase(iterator pos)
{
curr = head;
while(curr != pos.p)
{
curr = curr->next;
}
if(curr == NULL)
{
cout<<"can not find"<<endl;
}
else
{
node<T>* tmp = curr->next;
curr->next->front = curr->front;
curr->front->next = curr->next;
delete curr;
curr = NULL;
len--;
return iterator(tmp);
}
}
iterator erase(iterator start, iterator end)
{
node<T>* tmp = head;
node<T>* tmp2 = start.p;
curr = head;
while(curr != start.p)
{
curr = curr->next;
}
while(tmp != end.p)
{
tmp = tmp->next;
}
if(curr == NULL || tmp == NULL)
{
cout<<"can not find"<<endl;
}
else
{
int i = 1;
while(tmp2 != end.p)
{
tmp2 = tmp2->next;
i++;
}
tmp->front = curr->front;
curr->front->next = tmp;
delete curr;
delete tmp->front;
curr = NULL;
tmp->front = NULL;
len = len - i;
return iterator(tmp);
}
}
iterator insert(iterator pos, const T value)
{
curr = head;
while(curr != pos.p)
{
curr = curr->next;
}
node<T>* tmp = new node<T>(value);
curr->front->next = tmp;
tmp->front = curr->front;
tmp->next = curr;
curr->front = tmp;
return iterator(tmp);
}
void sort()
{
int i=0;
while(i<len)
{
node<T> *tmp = head;
node<T> *tmp1 = head->next;
node<T> *tmp2 = tmp1->next;
while(tmp2!=NULL)
{
if(tmp1->data>tmp2->data)
{
tmp->front = NULL;
tmp1->front = NULL;
tmp2->front = NULL;
tmp->next = tmp2;
tmp1->next = tmp2->next;
tmp2->next = tmp1;
tmp2->front = tmp;
tmp1->front =tmp2;
tmp = tmp2;
tmp2 = tmp1->next;
}
else
{
tmp = tmp1;
tmp1 = tmp2;
tmp2 = tmp2->next;
}
}
i++;
}
}
void insert(iterator pos, int num, const T value)
{
curr = head;
while(curr != pos.p)
{
curr = curr->next;
}
if(curr->next == NULL)
{
cout<<"can not find"<<endl;
}
node<T>* rt = NULL;
node<T>* rear = NULL;
node<T>* rhead = NULL;
int i;
for(i=0;i<num;i++)
{
rt = new node<T>(value);
if(i==0)
{
curr->front->next = rt;
rt->front = curr->front;
rear = rt;
rhead = rt;
}
rear->next = rt;
rt->front = rear;
rear = rt;
}
curr->front = rear;
rear->next = curr;
}
private:
int len;
node<T>* head;
node<T>* curr;
};
void show(list<int> l)
{
list<int>::iterator it;
for(it=l.begin();it!=l.end();it++)
{
cout<<*it<<endl;
}
}
int main(int argc, char *argv[])
{
list<int> l1;
l1.push_back(11);
l1.push_back(31);
l1.push_back(41);
l1.push_back(21);
l1.push_back(61);
l1.push_back(71);
l1.push_front(55);


list<int>::iterator ret;
ret = 11.begin();
//l1.insert(ret,5,100);
show(l1);
return 0;
}


0 0