昨天一个软件公司来面试,其中有几道编程题目:

rocket204 2006-05-13 05:51:17
1、编写一个逆3重法,在一个数组中a[n]中,0<i<j<k<n, ai>aj>ak,就输出{ai,aj,ak}例如:数组6,1,2,5,3,4 ,编写一个程序,要输出{6,5,3}或者{6,5,4}..

2、 13个人围成一圈,从第1个人开始顺序报号1、2、3。凡报到“3”者退出圈子,找出最后留在圈子中的人原来的序号。

3、编写程序,根据用户输入的数字(1~12),输出相应的月份名。用枚举类型实现。

我做了,但是不知道对不对,所以请教各位合适的编程语句,谢谢!
...全文
596 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
boxban 2006-05-15
  • 打赏
  • 举报
回复
凑个热闹
第一题:
//编写一个逆3重法,在一个数组中a[n]中,0<i<j<k<n, ai>aj>ak,就输出{ai,aj,ak}例如:数组6,1,2,5,3,4 ,编写一个程序,要输出{6,5,3}或者{6,5,4}..
#include <iostream>
#include <stdlib.h>

#define ASIZE(array) sizeof(array)/sizeof(array[0])

using namespace std;
void print(const int a[], int index, int i, int j, int k)
{
cout << "#" << index << '\t' << "a[" << i << ',' << j << ',' << k << "] = ";
cout << a[i] << ' ' << a[j] << ' ' << a[k] << endl;
}

void main()
{
int a[] = {6, 5, 4, 3, 7, 2, 5, 3, 4};
int cnt = 0;

cout << "a[] = ";
for (int m = 0; m < ASIZE(a); ++m)
cout << a[m] << ' ';
cout << endl;

for (int i = 0; i < sizeof(a)/sizeof(a[0]) - 2; ++i){
for(int j = i+1; j < sizeof(a)/sizeof(a[0]) - 1; ++j){
if (a[i] > a[j]){
for(int k = j+1; k < sizeof(a)/sizeof(a[0]); ++k){
if (a[j] > a[k]){
print(a, cnt++, i, j , k);
}
}
}
}
}

}
SamuelKevin 2006-05-15
  • 打赏
  • 举报
回复
软件公司来面试?
他找你?
你找他?
dhxcky 2006-05-14
  • 打赏
  • 举报
回复
很基础的咯,记得是大一时的题目。。。
tianhuo_soft 2006-05-14
  • 打赏
  • 举报
回复
13个人围成一圈,从第1个人开始顺序报号1、2、3。凡报到“3”者退出圈子,找出最后留在圈子中的人原来的序号。

最方便的就是用循环连表做
   建立连表我就不写了  你应该会


1 2 3 4 5 6 7 8 9 10 11 12
1 2 4 5 7 8 10 11
1 2 5 7 10 11
2 5 10 11
5 10
5
struct round{
int n;
struct round *next;
}

struct round *q,p;
q=head;
p=head->next;
do{
if(i%3==0){
q->next=p->next;
p->next=NULL;

}
q=p;
p=p->next;

i++;

}while(p!=NULL);
双杯献酒 2006-05-14
  • 打赏
  • 举报
回复
3、编写程序,根据用户输入的数字(1~12),输出相应的月份名。用枚举类型实现。

枚举类型只能表示整数,能表示“月份名”?
wumingchenchao 2006-05-14
  • 打赏
  • 举报
回复
so easy!
jiangjundu 2006-05-14
  • 打赏
  • 举报
回复
main()
{
int i,j=0,b[14];

b[0]=13;
for(i=1;i<14;b[i]=1,i++);
i=100;
while(1)
{
for(i=1;i<=13;i++)
{
if(b[i]&&b[0]>1)
{
j++;
if(j==3)
{
b[i]=0;
b[0]--;
j=0;
}

}
else if(b[i])
{
printf("%d",i);
return 0;
}
}

}

}
IhaveGotYou 2006-05-14
  • 打赏
  • 举报
回复
第三题:
#include <stdio.h>
#include <assert.h>
#include <malloc.h>
enum Month
{
Jan=1,
Feb,
Mar,
Apr,
May,
Jun,
Jul,
Aug,
Sep,
Oct,
Nov,
Dec
};

const char * PrintMonth(Month aMonth);

int main()
{
int theMonth;
printf("input the month(1~12) No:");
scanf("%d",&theMonth);
if(theMonth>=1 && theMonth<=12)
printf("%s\n",PrintMonth(Month(theMonth)));
else
printf("Error Month\n");
getchar();
return 0;
}

const char * PrintMonth(Month aMonth)
{
const char* MonthName[]={
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
return MonthName[aMonth-1];
}
defyer007 2006-05-13
  • 打赏
  • 举报
回复
I'M PASSER_BY...
f_acme 2006-05-13
  • 打赏
  • 举报
回复
对不对运行一下不就知道了?
hlnumber1 2006-05-13
  • 打赏
  • 举报
回复
都是老题目了,可见该公司很一般,也可见求才若渴
还是表示支持
yuanchuang 2006-05-13
  • 打赏
  • 举报
回复
so easy, you should code it yourself first.

69,381

社区成员

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

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