求助数组编程!!!!!!!!!!!!!急用!!!!!!!!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/25 11:36:01
百人出圈问题:设有100个人围坐一圈并按顺时针方向从1 到100编号,从第1个人开始进行1到10的报数,报数到第10个人,此人出圈。再从他的下一个人重新开始1到10的报数,如此进行下去直到所有的人都出圈为止,编写一个算法写出出圈的顺序。

字符串左右分别进行排序问题:有一行字符串,从字符串中间一分为二,左边部分按字符
的ASCII码值降值排序,右边部分按ASCII码升值排序,如果原字符串长度为奇数,则最中间的字符不参加排序,字符仍处于原来位置上。编写一个算法完成此操作。

Problem 1:

#include<stdio.h>
#include<string.h>

int out[101];
int n,now,cnt,i;

int main()
{
n = 100; now = cnt = 0;
while(cnt<n)
{
for(i=0;i<9;i++)
{
while(out[now]) now=(now==n-1?0:now+1);
now=(now==n-1?0:now+1);
}
while(out[now]) now=(now==n-1?0:now+1);
out[now] = 1; cnt++;
printf("%d is out of the game.\n",now+1);
}
printf("End of the game\n");
return 0;
}

Problem 2:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char s[1000];
int n;

int cmp1(const void *a,const void *b)
{
return *(char*)b-*(char*)a;
}

int cmp2(const void *a,const void *b)
{
return *(char*)a-*(char*)b;
}

int main()
{
printf("Input the string:\n");
gets(s);