C语言middleWord文档格式.docx
- 文档编号:6103279
- 上传时间:2023-05-06
- 格式:DOCX
- 页数:28
- 大小:20.69KB
C语言middleWord文档格式.docx
《C语言middleWord文档格式.docx》由会员分享,可在线阅读,更多相关《C语言middleWord文档格式.docx(28页珍藏版)》请在冰点文库上搜索。
intdis[3];
charfound;
inti,j,k;
%d%d%d"
hour+0,hour+1,hour+2)==3)
scanf("
speed+0,speed+1,speed+2);
found=0;
for(i=0;
i<
MAX_DAY&
&
!
found;
dis[0]=(i*24+hour[0])*speed[0];
for(j=0;
j<
j++)
dis[1]=(j*24+hour[1])*speed[1];
if(dis[0]==dis[1])lf\n"
p[n]);
Problem26菱形输出
/*两个字母间的空格用变量space控制,space初始值为1,
i:
2-n时,space=space+2
n+1-2n-2时,space=space-2
voidoutput(inti,intn,char*a)
intj;
for(j=i;
j>
1;
j--)
"
%c"
*a);
(*a)--;
for(j=0;
j<
2*(n-i)-1;
%c\n"
intn,i,j;
intr=0;
chara;
while(scanf("
&
n)==1)
if(r!
=0)printf("
r++;
a='
Z'
;
nv++nc++nv--nc--uit);
uit)
case'
S'
:
poker[i][j].v=4;
break;
H'
poker[i][j].v=3;
D'
poker[i][j].v=2;
C'
poker[i][j].v=1;
t);
alue=t-'
0'
switch(t)
A'
poker[i][j].value=14;
K'
poker[i][j].value=13;
Q'
poker[i][j].value=12;
J'
poker[i][j].value=11;
T'
poker[i][j].value=10;
qsort(poker[0],13,sizeof(structcard),cmp);
uit);
if(poker[i][j].value>
=10)
switch(poker[i][j].value)
case14:
printf("
A"
case13:
K"
case12:
Q"
case11:
J"
case10:
T"
poker[i][j].value);
Problem32乒乓球
voidsolve(char*str,intbase);
charstr[100],ts[31];
intlen;
inti;
intw,l;
while(gets(ts)!
=NULL)
strcpy(str,ts);
len=strlen(ts);
while(ts[len-1]!
='
E'
)
gets(ts);
strcat(str,ts);
}otorcycleType);
}
voidinput()
n;
i++)otorcycleType,motor[i].color,motor[i].motorType);
motor[i].f=0;
intFindMotor(char*motorName)otorcycleType,motorName)==0)
returni;
return-1;
voidslv()
inti,j;
intfound=0;
i++)
j=FindMotor(motorList[i]);
if(j!
=-1)
{
motor[j].f=1;
found=1;
}
if(!
found)
printf("
Cannotfound!
m;
if(motor[i].f)
%s%s%s\n"
motor[i].motorcycleType,motor[i].color,motor[i].motorType);
%d%d"
n,&
m)==2)
input();
qsort(motor,m,sizeof(structMotor),cmp);
因为要求最先出列的k个人都是绑匪,如果m<
=k,则第1个出列的就是人质,所以m>
=k+1。
所以m(外循环变量i)可以k+1、k+2…进行枚举。
4.针对每个m,参与游戏的人数(内循环变量i)依次为2k、2k-1…k+1。
i个人报数时,该出列的人的编号计算公式为s=(s+m)%i,如果s>
k(第k到第i-1个绑匪)或s=0(第i个绑匪),则表示出列的是绑匪,否则是人质。
5.内循环时,如果出列的是人质,则表示当前的m不合适,这时离开内循环,开始下一轮外循环;
如果出列的是绑匪,则进行下一轮内循环。
如果内循环正常结束,则表示出列的k个人都是绑匪,结束外循环,输出找到的m即可。
intk,m;
intfind,s,i;
k)==1)
m=k;
do
m++;
find=1;
.、2位数、1位数
sum=0;
for(cnt=0;
cnt<
len;
cnt++)//将str[j]开始长度为len的数字子串转换为整型数
sum=sum*10+str[j+cnt]-'
}
if(isprime(sum)&
sum>
max)
max=sum;
}
len--;
%d\n"
max);
Problem46日期比较
intd1,m1,y1;
intd2,m2,y2;
voidprinta()
%02d%02d%disearlierthan%02d%02d%d\n"
d1,m1,y1,d2,m2,y2);
voidprintb()
d2,m2,y2,d1,m1,y1);
%d%d%d%d%d%d"
d1,&
m1,&
y1,&
d2,&
m2,&
y2)!
=EOF)
if(y1<
y2)printa();
elseif(y2<
y1)printb();
elseif(m1<
m2)printa();
elseif(m2<
m1)printb();
elseif(d1<
d2)printa();
elseprintb();
Problem47魔方阵
intmain(){
inta[19][19];
intcolumn,line,num;
intnextColumn,nextLine;
n)!
memset(a,0,sizeof(a));
column=n/2;
//规则1
line=0;
for(num=1;
num<
=n*n;
num++)//构造魔方阵
a[line][column]=num;
nextLine=line-1;
//规则2
nextColumn=column+1;
if(nextLine<
0)nextLine=n-1;
//规则3
if(nextColumn==n)nextColumn=0;
//规则4
if(a[nextLine][nextColumn]!
=0||(line==0&
column==n-1))//规则5
line=line+1;
if(line>
=n)line=0;
else
line=nextLine;
column=nextColumn;
for(i=0;
n;
printf("
a[i][0]);
for(j=1;
j++){
printf("
%d"
a[i][j]);
Problem48最长的单词
chartemp[1000],rs[1000];
while(gets(temp)!
intmaxLen=0,len;
char*p=strtok(temp,"
\n"
//在temp中,以空格和换行符为分割符寻找单词
while(p)
len=strlen(p);
if(len>
maxLen)
maxLen=len;
strcpy(rs,p);
p=strtok(NULL,"
//第2次开始后的调用
%d%s\n"
maxLen,rs);
Problem49奖学金
intfinalScore,appraiseScore,thesis;
charcadre,west,name[21],max_name[21];
intn;
intsum=0,max=-1,i;
if(r!
r++;
for(i=0;
i++)
inttemp=0;
//某个学生的奖学金
%s%d%d%*c%c%*c%c%d"
name,&
finalScore,&
appraiseScore,&
cadre,&
west,&
thesis);
//ok
//scanf("
%s%d%d%1s%*c%c%d"
%s%d%d%*c%c%1s%d"
//NO
%s%d%d%1s%1s%d"
if(finalScore>
80&
thesis>
0)//院士奖学金
temp+=8000;
85&
appraiseScore>
80)//五四奖学金
temp+=4000;
90)//成绩优秀奖
temp+=2000;
'
Y'
==west)//西部奖学金
temp+=1000;
if(appraiseScore>
80&
==cadre)//班级贡献奖
temp+=850;
if(temp>
max){
max=temp;
strcpy(max_name,name);
sum+=temp;
}
%s\n%d\n%d\n"
max_name,max,sum);
Problem50序列
/*放球方法:
后1个盒子中比前1个盒子多放1个球;
最后剩余的remain个球依次从最后1个盒子开始往前,每个盒子增加1个,直到放完为止。
该方法能保证小球装入盒子的规则
*/
intballCnt;
intbox[140];
//10000-(1+n)*n/2<
=n,n的大小为140
intremain;
//还未放入盒子中的球数
intlastBox;
//最后一个盒子中放的球数
intboxCnt;
//放有球的盒子总数
ballCnt)!
=EOF&
ballCnt)
remain=ballCnt;
lastBox=0;
for(i=0;
remain>
lastBox;
box[i]=i+1;
remain-=i+1;
lastBox=box[i];
boxCnt=i;
while(remain>
0)
i--;
box[i]++;
remain--;
boxCnt-1;
%d,"
box[i]);
Problem51树
intL,M;
charroad[10001];
//1:
代表有树;
0:
代表树已移走
intcnt,i,j;
intleft,right;
while(scanf("
L,&
M)!
=EOF){
memset(road,1,L+1);
//road数组的前L+1个字节置初始值1
cnt=L+1;
//初始树的棵数
M;
left,&
right);
for(j=left;
=right;
if(road[j]){
cnt--;
road[j]=0;
cnt);
Problem52三角形
ints,n;
intr=0,i,j;
s,&
n)==2)
=0)
=n;
i++)//控制输出的行数
for(j=1;
=i;
j++)//控制每行输出的数字个数
s);
if(j<
i)
s=s%9+1;
//计算下一次输出的数字
Problem53回文数2
/*middle53:
给你一个整数(十进制),
判断该整数的十进制数和它的二进制数是否全为回文数。
intisPalindrome(char*number);
{
chardecimal[4];
//(0,1000),十进制不超过3位
charbinary[11];
//(0,1000),二进制不超过10位
itoa(n,binary,2);
//将n转换成2进制的数字字符串,存放到binary中
itoa(n,decimal,10);
//将n转换成10进制的数字字符串,存放到decimal中
if(isPalindrome(decimal)&
isPalindrome(binary))
Yes\n"
No\n"
intisPalindrome(char*number)//判断number所指向的数是否是回文数
char*head=number;
char*tail=head+strlen(number)-1;
while(head<
tail)
if(*head!
=*tail)
head++;
tail--;
return1;
Problem54加法器
//与easy45题类似,且更简单
char*p;
//存放分离出来的数字字符串
chartemp[1001];
intsum,tint;
sum=0;
p=strtok(temp,"
+"
//第1次分离
tint=atoi(p);
//数字字符串转换成整数
sum+=tint;
p=strtok(NULL,"
//第2次开始分离
sum);
Problem55数列1
intarr[50];
inti,j,cnt,sum;
cnt=0;
for(i=0;
arr+i);
i<
i++)
sum=0;
for(j=i;
sum+=arr[j];
if(sum%11==0)
cnt++;
}
Problem56数列2
intarr[15];
intn,i,j,cnt,tmp,res;
for(i=1;
=((1<
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 middle