几道笔试题目,大家讨论哈

qong 2005-11-09 01:55:34
1.设计函数 int atoi(char *s)
2. What do the following declarations mean?
  (1)const int a;
  (2)int const a;
  (3)const int *a;
  (4)int * const a;
  (5)int const * a const;
3.编程
  将整数转换成字符串:void itoa(int,char);
  例如itoa(-123,s[])则s=“-123”;
4.10个人分成4组 有几种分法?(程序)(不能重复,如:1,1,1,7=7,1,1,1)
5.如图:
     7 8 9 10
     6 1 2 11
     5 4 3 12
    16 15 14 13
    设“1”的坐标为(0,0) “7”的坐标为(-1,-1) 编写一个小程序,使程序做到输入坐标(X,Y)之后显示出相应的数字。
6.编最优化Bubble(int *pIntArray,int L),要求:交换元素不能用临时变量,如果有序需要最优。
...全文
1070 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
vc_tapi 2006-02-11
  • 打赏
  • 举报
回复
mark
luvybird 2006-01-05
  • 打赏
  • 举报
回复
mark
haiqing2004 2005-11-12
  • 打赏
  • 举报
回复
在vc下,hannergsx(喊)的说法(3)跟(5)似乎不对哦:
例如:
#include<iostream.h>


void main()
{
int b=3;
const int* a=&b;
cout<<*a;
b++;
cout<<*a;

}
输出34;所以说法const int *a;指针a指向的数据不允许改变是错的;
(5)同理啦
windeflower 2005-11-11
  • 打赏
  • 举报
回复
4
#include <stdio.h>

main()
{
int group[4];
int sum;

group[0] = group[1] = group[2] = 1;
group[3] = 7;

sum = 1;

printf("%d\t%d\t%d\t%d\t\n",group[0],group[1],group[2],group[3]);

for(int i = 0; i < 3; i++)
{
while (group[i] < group[3] )
{
group[i]++;
group[3]--;

if (group[i] <= group[3])
{
printf("%d\t%d\t%d\t%d\t\n",group[0],group[1],group[2],group[3]);
sum++;
}
}
group[i] = 2;
group[3] = 6 -i ;
}
printf("sum:%d\n",sum);
}
RedWolf1999 2005-11-10
  • 打赏
  • 举报
回复
void bubble (int *A,int n)//n--数组元素个数
{
int i,j;
bool change;
for (i=n-1,change=true; i>0 && change; --i)
{
change = false;
for (j=0; j<i; ++j)
if (A[j]>A[j+1])
{
A[j] = A[j]+A[j+1];
A[j+1] = A[j]-A[j+1];
A[j] = A[j]-A[j+1];
change = true;
}
}
}
李黄河 2005-11-10
  • 打赏
  • 举报
回复
void bubble (int *a,int n)//n--数组元素个数
{
int i ,j ,k;
for(k=n-1;k>0;k=j)
for(i=j=0;i<k;++i)
{
if(a[i]>a[i+1])
{
a[i]=a[i]^a[i+1];
a[i+1]=a[i]^a[i+1];
a[i]=a[i]^a[i+1];
j=i;
}
}
李黄河 2005-11-10
  • 打赏
  • 举报
回复
void bubble (int* a,int n)
{

}
pengjay 2005-11-10
  • 打赏
  • 举报
回复
5:
#include <iostream.h>

int main()
{
int x1;
int y1;
cout<<"input x1:";
cin>>x1;
cout<<"input y1:";
cin>>y1;
int m=1;
long n=1;
int t=1;
int i=0;
int j=0;

while(1)
{
for(m=1;m<=t;m++)
{
j++;n++;
if(j==y1&&i==x1) goto end;
}

for(m=1;m<=t;m++)
{
i++;n++;
if(j==y1&&i==x1) goto end;
}
t++;

for(m=1;m<=t;m++)
{
j--;n++;
if(j==y1&&i==x1) goto end;
}

for(m=1;m<=t;m++)
{
i--;n++;
if(j==y1&&i==x1) goto end;
}
t++;

}
end:
cout<<n<<endl;

return 0;
}
boylez 2005-11-10
  • 打赏
  • 举报
回复
第五题:先找到所有平方数的位置,是有规律的:
奇数平方数1,9,25……在从1开始想右上直线延伸,4,16,36……从4开始向左下直线延伸,这样可以快速确定平方数位置。输入n,求得n两边的平方数,例如输入27,则确定25和36位置,中间从26到36的5+6=11个数位置就是联系排列,只有一个拐弯,在26+5=31处,接下来不就ok了?
viyar 2005-11-10
  • 打赏
  • 举报
回复
itoa 最方便的方法
sprintf(buf, "%d", n);
zdx19814 2005-11-10
  • 打赏
  • 举报
回复
int atoi(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 */
}
李黄河 2005-11-10
  • 打赏
  • 举报
回复
.10个人分成4组 有几种分法?(程序)(不能重复,如:1,1,1,7=7,1,1,1)
int cc(int m,int n)
{
int cnt=0;
if(1==n) return 1;
if(m==n) return 1;
if(m==n+1 ) return 1;
if(m>n+1)
{
int j=((m-n)>n?n:m-n);
for(int i=1;i<=j;++i)
cnt+=cc(m-n,i);
}
return cnt;
}
cc(10,4)=9种
oceanblueboy 2005-11-10
  • 打赏
  • 举报
回复
1.#include<iostream.h>
#include<string.h>
#include<math.h>
int myatoi ( char *s )
{
int len = strlen( s );
char temp ;
int i = 0;
int value = 0;
while( temp = *s++ )
{


value += (int) (temp-48) *(int) pow( 10 , len-1-i );
i++;

}
return value;

}
void main()
{
char test[] = "1234";
cout<<myatoi(test);


}
amitabha 2005-11-10
  • 打赏
  • 举报
回复
mk
cnsdwfwy 2005-11-10
  • 打赏
  • 举报
回复
void CheckItOut(int n)
{
// TODO: Add your control notification handler code here
int i,j,nForwardCount,nDirection,nForwardCountLimit,k;
i=j=0;
nForwardCountLimit = 1;
nForwardCount = 0;
nDirection = 1;
k=1;

for (;k<n;)
{
if (nForwardCount>=nForwardCountLimit)
{
nForwardCount = 0;
if (nDirection==4)
{
nDirection = 1;
++nForwardCountLimit ;
}
else if (nDirection ==2)
{
++nDirection;
++nForwardCountLimit;
}
else
{
++nDirection ;
}
}
switch(nDirection)
{
case 1:
++i;
break;
case 2:
++j;
break;
case 3:
--i;
break;
case 4:
--j;
break;
}
++nForwardCount;
++k;
}

}
输入参数n,运行结束后的i,j值就是坐标。
fjm_520 2005-11-10
  • 打赏
  • 举报
回复
强啊
jack_mars195 2005-11-10
  • 打赏
  • 举报
回复
3.编程
  将整数转换成字符串:void itoa(int,char);
  例如itoa(-123,s[])则s=“-123”;
void itoa(int num){
int i,n,m,temp;
char cha[12];
temp = num;
for(n = 1;temp /= 10;n++);
m = n;
if(num < 0){
cha[0] = '-';
num *= -1;
for(i = 0;i < n;i++){
temp = num % 10;
cha[m] = (char)(temp+48);
num /= 10;
m--;
}
cha[n+1] = '\0';
}
else{
for(i = 0;i < n;i++){
temp = num % 10;
cha[m-1] = (char)(temp+48);
num /= 10;
m--;
}
cha[n] = '\0';
}
cout<<"The result is: ";
for(i = 0;i < n+1;i++)
cout<<cha[i];
cout<<endl;
}
「已注销」 2005-11-09
  • 打赏
  • 举报
回复
网易群去年和今年的比试题目,昨天刚考完,一看见就有点崩溃的感觉
jack_mars195 2005-11-09
  • 打赏
  • 举报
回复
5.如图:
     7 8 9 10
     6 1 2 11
     5 4 3 12
    16 15 14 13
    设“1”的坐标为(0,0) “7”的坐标为(-1,-1) 编写一个小程序,使程序做到输入坐标(X,Y)之后显示出相应的数字。
#include <iostream.h>
int x1=0,y1=0,x2=0,y2=0;
int main(){
int i,j,n,num=1;
cout<<"Please input x-coordinate: ";
cin>>x1;
cout<<"Please input y-coordinate: ";
cin>>y1;
for(i = 2;i < 6;i++)
for(n = 0;n < 2;n++)
for(j = 1;j < i;j++){
if(i % 2){
if(n == 0){
if((x1 == x2)&&(y1 == y2))
break;
y2--;
num++;
}
else{
if((x1 == x2)&&(y1 == y2))
break;
x2--;
num++;
}
}
else{
if(n == 0){
if((x1 == x2)&&(y1 == y2))
break;
y2++;
num++;
}
else{
if((x1 == x2)&&(y1 == y2))
break;
x2++;
num++;
}
}
}
cout<<"x-coordinate: "<<x1<<" y-coordinate: "<<y1<<endl;
cout<<"The number is: "<<num<<endl;
return 0;
}
liegou2000 2005-11-09
  • 打赏
  • 举报
回复

掉了

void bubble(int *a,int n)
{
int i,j,change;
for(i=1,change=1; i<n && change; ++i)
{
change = 0;
for (j=0; j<n-i; ++j)
if (a[j] > a[j+1])
{
a[j]=a[j]^a[j+1];
a[j+1]=a[j+1]^a[j];
a[j]=a[j]^a[j+1];
change=true;
}
}
}
加载更多回复(5)

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧