机试试题及代码文档格式.docx

上传人:b****2 文档编号:882909 上传时间:2023-04-29 格式:DOCX 页数:49 大小:26.90KB
下载 相关 举报
机试试题及代码文档格式.docx_第1页
第1页 / 共49页
机试试题及代码文档格式.docx_第2页
第2页 / 共49页
机试试题及代码文档格式.docx_第3页
第3页 / 共49页
机试试题及代码文档格式.docx_第4页
第4页 / 共49页
机试试题及代码文档格式.docx_第5页
第5页 / 共49页
机试试题及代码文档格式.docx_第6页
第6页 / 共49页
机试试题及代码文档格式.docx_第7页
第7页 / 共49页
机试试题及代码文档格式.docx_第8页
第8页 / 共49页
机试试题及代码文档格式.docx_第9页
第9页 / 共49页
机试试题及代码文档格式.docx_第10页
第10页 / 共49页
机试试题及代码文档格式.docx_第11页
第11页 / 共49页
机试试题及代码文档格式.docx_第12页
第12页 / 共49页
机试试题及代码文档格式.docx_第13页
第13页 / 共49页
机试试题及代码文档格式.docx_第14页
第14页 / 共49页
机试试题及代码文档格式.docx_第15页
第15页 / 共49页
机试试题及代码文档格式.docx_第16页
第16页 / 共49页
机试试题及代码文档格式.docx_第17页
第17页 / 共49页
机试试题及代码文档格式.docx_第18页
第18页 / 共49页
机试试题及代码文档格式.docx_第19页
第19页 / 共49页
机试试题及代码文档格式.docx_第20页
第20页 / 共49页
亲,该文档总共49页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

机试试题及代码文档格式.docx

《机试试题及代码文档格式.docx》由会员分享,可在线阅读,更多相关《机试试题及代码文档格式.docx(49页珍藏版)》请在冰点文库上搜索。

机试试题及代码文档格式.docx

if(year%400==0||(year%100!

=0&

&

year%4==0))

{inttemp,flag=mount;

intmonth=1,day;

for(inti=0;

year1[i]<

mount;

i++)

{mount=mount-year1[i];

}

day=mount;

month=i;

printf("

%d-%.2d-%.2d"

year,month+1,day);

else{

inttemp,flag=mount;

year2[i]<

{mount=mount-year2[i];

}}}

2

题目描述:

 

Excel可以对一组纪录按任意指定列排序。

现请你编写程序实现类似功能。

对每个测试用例,首先输出1行“Casei:

”,其中i是测试用例的编号(从1开始)。

随后在N行中输出按要求排序后的结果,即:

当C=1时,按学号递增排序;

当C=2时,按姓名的非递减字典序排序;

当C=3 

时,按成绩的非递减排序。

当若干学生具有相同姓名或者相同成绩时,则按他们的学号递增排序。

测试输入包含若干测试用例。

每个测试用例的第1行包含两个整数N(N<

=100000)和C,其中N是纪录的条数,C是指定排序的列号。

以下有N行,每行包含一条学生纪录。

每条学生纪录由学号(6位数字,同组测试中没有重复的学号)、姓名(不超过8位且不包含空格的字符串)、成绩(闭区间[0,100]内的整数)组成,每个项目间用1个空格隔开。

当读到N=0时,全部输入结束,相应的结果不要输出。

31

000007James85

000010Amy90

000001Zoe60

42

000002James98

43

000002James90

00

Case1:

Case2:

Case3:

代码

#include<

stdio.h>

stdlib.h>

string.h>

structstudent

{charid[7];

charname[9];

intscore;

};

intmain()

{

intn,c,i,j;

structstudent*stu,temp;

while(scanf("

%d%d"

n,&

c)!

=EOF)

{stu=(student*)malloc(n*sizeof(student));

for(i=0;

i<

n;

{scanf("

%s%s%d"

stu[i].id,&

stu[i].name,&

stu[i].score);

}

switch(c)

{case1:

{for(i=0;

{for(j=i;

j<

j++)

if(strcmp(stu[i].id,stu[j].id)>

0)

{temp=stu[i];

stu[i]=stu[j];

stu[j]=temp;

printf("

\n"

);

%s%s%d\n"

stu[i].id,stu[i].name,stu[i].score);

break;

case2:

{if(strcmp(stu[i].name,stu[j].name)>

if(strcmp(stu[i].name,stu[j].name)==0)

{if(strcmp(stu[i].id,stu[j].id)>

case3:

{if(stu[i].score>

stu[j].score)

if(stu[i].score==stu[j].score)

return0;

 

对输入的n个数进行排序并输出。

输入的第一行包括一个整数n(1<

=100)。

接下来的一行包括n个整数。

可能有多组测试数据,对于每组数据,将排序后的n个整数输出,每个数后面都有一个空格。

每组测试数据的结果占一行。

4

1432

1234

malloc.h>

voidmain()

{

intn,i,j,t;

while(scanf("

n)!

int*a;

a=(int*)malloc(n*sizeof(int));

{

scanf("

a[i]);

for(j=i+1;

if(a[i]>

a[j])

t=a[i];

a[i]=a[j];

a[j]=t;

%d"

a[i]);

有N个学生的数据,将学生数据按成绩高低排序,如果成绩相同则按姓名字符的字母序排序,如果姓名的字母序也相同则按照学生的年龄排序,并输出N个学生排序后的信息。

测试数据有多组,每组输入第一行有一个整数N(N<

=1000),接下来的N行包括N个学生的数据。

每个学生的数据包括姓名(长度不超过100的字符串)、年龄(整形数)、成绩(小于等于100的正数)。

将学生信息按成绩进行排序,成绩相同的则按姓名的字母序进行排序。

然后输出学生信息,按照如下格式:

姓名年龄成绩

3

abc2099

bcd1997

bed2097

#include<

structnode

charname[101];

intage;

intscore;

intn,i,j;

structnodea[1001],tmp;

for(i=0;

%s%d%d"

a[i].name,&

a[i].age,&

a[i].score);

n-1;

for(j=0;

n-1-i;

if(a[j].score>

a[j+1].score)

tmp=a[j];

a[j]=a[j+1];

a[j+1]=tmp;

}//if

elseif(a[j].score==a[j+1].score)

if(strcmp(a[j].name,a[j+1].name)>

elseif(strcmp(a[j].name,a[j+1].name)==0)

if(a[j].age>

a[j+1].age)

}//elseif

}//for

%s%d%d\n"

a[i].name,a[i].age,a[i].score);

}//while

return0;

输入一系列整数,将其中最大的数挑出,并将剩下的数进行排序。

输入第一行包括1个整数N,1<

=N<

=1000,代表输入数据的个数。

接下来的一行有N个整数。

第一行输出一个整数,代表N个整数中的最大值,并将此值从数组中去除,将剩下的数进行排序。

第二行将排序的结果输出。

1342

123

intmain(){

inti,n,t,j,a[1000];

i++){

j=i-1;

while(j>

=0&

a[j]>

t){a[j+1]=a[j];

j--;

a[j+1]=t;

%d\n"

a[n-1]);

if(n==1)printf("

-1\n"

elsefor(i=0;

if(i!

=n-2)printf("

"

elseprintf("

输入一个字符串,长度小于等于200,然后将输出按字符顺序升序排序后的字符串。

测试数据有多组,输入字符串。

对于每组输入,输出处理后的结果。

bacd

abcd

string.h"

chara[200];

chartem;

%s"

a)!

intlen=strlen(a);

len;

for(intj=i+1;

if(a[i]>

tem=a[i];

a[i]=a[j];

a[j]=tem;

for(intm=0;

m<

m++)

%c"

a[m]);

有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天

有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD

每组数据输出一行,即日期差值

20110412

20110422

11

intcountDates(int,int,int);

inty1,m1,d1,y2,m2,d2;

intdays1,days2,day;

%4d%2d%2d"

&

y1,&

m1,&

d1)!

=EOF)

y2,&

m2,&

d2);

days1=countDates(y1,m1,d1);

days2=countDates(y2,m2,d2);

if(days1>

days2)

day=days1-days2+1;

}else

day=days2-days1+1;

day);

intcountDates(intyear,intmonth,intday)

intnumber,i;

intm[12]={31,28,31,30,31,30,31,31,30,31,30,31};

if((year%4==0)&

(year%100!

=0)||(year%400==0))

m[1]=29;

number=(year-1)*365+(year-1)/4-(year-1)/100+(year-1)/400;

//统计闰年的天数加上平年

for(i=0;

i<

month-1;

i++)

number+=m[i];

number+=day;

returnnumber;

代码2

//先整体求天数最后再统计闰年的天数

intm[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

intleap(intn)

if(n%4==0&

n%100!

=0||n%400==0)

return1;

else

intcomday(inty1,intm1,intd1)

intsum=0,i;

for(i=1;

m1;

sum+=m[i];

sum+=d1;

if(leap(y1)&

m1>

2)

sum++;

returnsum;

intcompute(inty,intm,intd)

intsum=0;

inti;

sum=(y-1)*365+comday(y,m,d);

y;

if(leap(i))

chars1[10],s2[10];

inty1,y2,m1,m2,d1,d2,i;

y1,&

m1,&

d1)!

y2,&

m2,&

compute(y2,m2,d2)-compute(y1,m1,d1)+1);

return0;

WenowusetheGregorianstyleofdatinginRussia.Theleapyearsareyearswithnumberdivisibleby4butnotdivisibleby100,ordivisibleby400.

Forexample,years2004,2180and2400areleap.Years2004,2181and2300arenotleap.

Yourtaskistowriteaprogramwhichwillcomputethedayofweekcorrespondingtoagivendateinthenearestpastorinthefutureusingtoday’sagreementaboutdating.

Thereisonesinglelinecontainsthedaynumberd,monthnameMandyearnumbery(1000≤y≤3000).ThemonthnameisthecorrespondingEnglishnamestartingfromthecapitalletter.

OutputasinglelinewiththeEnglishnameofthedayofweekcorrespondingtothedate,startingfromthecapitalletter.Allotherlettersmustbeinlowercase.

9October2001

14October2001

Tuesday

Sunday

提示:

MonthandWeeknameinInput/Output:

January,February,March,April,May,June,July,August,September,October,November,December

Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday

//先算出总的天数,由总天数再除以7就得是第几天

intconvert(chars[])

charmonth[12][10]={"

January"

"

February"

March"

April"

May"

June"

July"

August"

September"

October"

November"

December"

for(inti=0;

12;

++i)

if(strcmp(s,month[i])==0)

return(i+1);

intmain(void)

intday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

charweek[7][10]={"

Sunday"

Monday"

Tuesday"

Wednesday"

Thursday"

Friday"

Saturday"

intD,Y;

charm[10];

%d%s%d"

D,m,&

Y)!

inti,M=convert(m),e=(Y-1)*365;

//e代表总的天数

for(i=1;

Y;

if((i%4==0&

i%100!

=0)||i%400==0)

++e;

M;

e+=day[i];

if(((Y%4==0&

Y%100!

=0)||Y%400==0)&

M>

2)

e+=D;

%s\n"

week[e%7]);

输入年、月、日,计算该天是本年的第几天。

包括三个整数年(1<

=Y<

=3000)

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2