通过这次的笔试,感觉题目都很简单,但当下来对程序实现的时候,发现好多地方考虑的不够周到,下面将题目自己总结了一下,有什么问题希望大家提出来,一起学习!!
1、链表两两逆置(不用指针的倒换,直接用倒数据就可以)
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef struct node
{
int data;
struct node *next;
}node;
node *create()
{
int n=6;
node *head=(node *)malloc(sizeof(node)),*p,*s;
head->data=0;
p=head;
for(int i=1;i<n;i++)
{
s=(node *)malloc(sizeof(node));
s->data=i;
p->next=s;
p=p->next;
}
p->next=NULL;
return head;
}
void print(node *head)
{
int n=6;
node *p;
p=head;
while(p)
{
cout<<p->data<<" ";
p=p->next;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
node *head=create(),*p,*q;
p=head;
if(!p)
return 0;
q=p->next;
while(p&&q)
{
//a=a^b;
//b=a^b;
//a=a^b;
p->data=p->data^q->data;
q->data=p->data^q->data;
p->data=p->data^q->data;
p=p->next->next;
if(p)
q=q->next->next;
else break;
}
print(head);
cout<<endl;
system("pause");
return 0;
}
2、一个有序数组和一个数,数组中的两个数的和等于该数,求这个两个数,时间复杂试为O(n)
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a[]={1,2,4,7,11,15};
int m=15;
int n=6;
int begin=0,end=n-1;;
while(begin<end)
{
if(a[begin]+a[end]<m)
{
begin++;
}
else if(a[begin]+a[end]>m)
{
end--;
}
else
{
cout<<a[begin]<<" "<<a[end];
break;
}
}
cout<<endl;
system("pause");
return 0;
}
3、I am a student.输出student. a am I(标点不动)
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//第̨²一°?种?方¤?法¤¡§,ê?从䨮后¨®向¨°前¡ã,ê?遇®?到Ì?空?格?部?分¤?输º?出?。¡ê
/*
char c[]="I am a student.";
//char c[]="I come from tianjin.";
int len=strlen(c);
int begin=len,end=0;
for(int i=len-1;i>=0;i--)
{
if(c[i]==' ')
{
end=begin;
begin=i;
for(int j=begin+1;j<=end-1;j++)
{
cout<<c[j];
}
cout<<" ";
}
}
begin=0;
for(int k=0;k<len;k++)
{
if(c[k]==' ')
{
end=k;
break;
}
}
for(int m=begin;m<end;m++)
{
cout<<c[m];
}
cout<<endl;
system("pause");
return 0;*/
//第̨²二t种?方¤?法¤¡§,ê?先¨¨全¨?盘¨¬倒Ì1换?,ê?然¨?后¨®从䨮前¡ã往ª¨´后¨®,ê?遇®?到Ì?空?格?在¨²倒Ì1换?
char c[]="I am a student.";
//char c[]="I come from tianjin.";
int len=strlen(c);
int begin=0,end=len-1,tmp;
while(begin<end)
{
tmp=c[begin];
c[begin]=c[end];
c[end]=tmp;
begin++;
end--;
}
begin=0;
end=-2;
int b,e;
for(int i=0;i<len;i++)
{
if(c[i]==' ')
{
begin=end+2;
end=i-1;
b=begin;
e=end;
while(b<e)
{
tmp=c[b];
c[b]=c[e];
c[e]=tmp;
b++;
e--;
}
}
}
for(int m=0;m<len;m++)
{
cout<<c[m];
}
cout<<endl;
system("pause");
return 0;
}
4、约瑟夫环,最后一个输出是几,环中n个数,从0~n-1,数到第m个数删除
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef struct node
{
int data;
struct node *next;
}node;
node *create(int n)
{
node *head=(node *)malloc(sizeof(node)),*p,*s;
head->data=0;
p=head;
for(int i=1;i<n;i++)
{
s=(node *)malloc(sizeof(node));
s->data=i;
p->next=s;
p=p->next;
}
p->next=head;
return head;
}
void print(node *head,int n)
{
node *p;
cout<<head->data<<" ";
p=head->next;
while(p!=head)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
int n=5,m=2,count=1;
print(create(n),n);
node *head=create(n),*p=head,*q;
while(p->next!=p)
{
while(count!=m)
{
q=p;
p=p->next;
count++;
}
count=1;
cout<<p->data<<" ";
q->next=q->next->next;
p=q->next;
}
cout<<p->data;
cout<<endl;
system("pause");
return 0;
}
5、Customer(ID,Name)
Order(ID,CustId,Revenue)
选出Customer的Revenuer的和
use DBName
--使用SUM函数,Order与数据库关键字冲突,要使用[]
--连接查询
--此外不能只写Customer.ID,select中出现的字段(除聚合函数),必须出现在group by中,group by中出现的字段应大于等于select后的字段(除聚合函数)
select Customer.Name,SUM([Order].Revenue)
from Customer,[Order]
where Customer.ID=[Order].CustId
group by Customer.Name
6、翻译
data form:数据表单
list:列表
optional method:可选择的方法
enter information:输入信息
field:字段名
data menu:数据菜单
在一个列表中,表单提供一种输入信息的可选择的方法。一旦字段名被输入,你可以使用数据菜单来访问数据表单。甚至起初你不用选择列表的范围,只要当数据表单打开时,活动的单元格在列表范围内,电子表格将自动定位列表。
随着你向表单中增加新的记录,列表的范围将使用新的行不断的更新,电子表格自动增加列表的范围。
7、
As the development of science and technology, more and more people use the Internet;they enjoy downloading various kinds of materials.Someone likes to download free music especially, they think that downloading free music not only enriches our lives, but also is beneficial to music industry, because it contributes to increasing the music popularity.