Ⅰ c語言奧運會開幕式
這是一個約瑟夫環的問題。這個問題c語言實現代碼如下:
#include <stdio.h>
#include <stdlib.h>
struct _Node
{
int data;
struct _Node *next;
};
typedef struct _Node node_t;
typedef struct _Linklist
{
node_t * phead;
node_t * ptail;
int len;
}Linklist;
static node_t * GetNode( int i ) // 新建並初始化節點
{
node_t *pNode;
pNode = ( node_t * )malloc( sizeof( node_t ) );
if(!pNode)
{
printf("Error,the memory is not enough!\n");
exit(-1);
}
pNode -> data = i;
pNode -> next = NULL;
return pNode;
}
void init_list( Linklist *plist ) // 用第一個節點初始化循環單鏈表
{
node_t *p;
p = GetNode( 1 );
// printf("The New Node is: %d\n", p -> data); // **** TEST ****
plist -> phead = p;
plist -> ptail = p;
p -> next = plist -> phead;
plist -> len = 1;
}
static void Create_List( Linklist *plist, int n ) // 把其餘數據添加到循環單鏈表中
{
int i = 0;
node_t *pNew;
for(i=2;i<=n;i++)
{
pNew = GetNode( i );
/******** TEST ********
printf("The New Node is: %d\n", pNew -> data);
******** TEST ********/
plist -> ptail -> next = pNew;
plist -> ptail = pNew;
pNew -> next = plist -> phead;
plist -> len ++;
}
printf("Completes the e-way circulation chain table the foundation!\n");
}
void Print_List( Linklist *plist ) // 輸出鏈表內容
{
node_t *pCur = plist -> phead;
do
{
printf("The %d person.\n", pCur -> data );
pCur = pCur -> next;
}while( pCur != plist -> phead );
printf("The length of the List: %d\n", plist -> len );
}
void joseph( Linklist *plist, int m ) //約瑟夫回環函數實現
{
node_t *pPre = plist -> ptail;
node_t *pCur = plist -> phead;
int i;
while( plist -> len != 1 )
{
i = 0;
while( i < m-1 )
{
pPre = pPre -> next;
i ++;
}
pCur = pPre -> next;
pPre -> next = pCur -> next;
free( pCur );
plist -> len --;
}
printf("The last one is: %d\n", pPre -> data );
}
int main()
{
int n = 0;
printf("輸入學生人數 ");
scanf("%d", &n );
int m = 0;
printf("輸入m的值 ");
scanf("%d", &m );
Linklist pList;
init_list( &pList );
Create_List( &pList, n );
Print_List( &pList );
joseph( &pList, m );
return 0;
}
Ⅱ C語言:用數組解答運動會標槍冠軍
#include<stdio.h>
int main()
{
int g=0,n,i,d;
double x,y,l;
scanf("%d\n",&n);
for(i=1;i<=n;i++){
scanf("%lf %lf\n",&x,&y);
l=x*x+y*y;
if(g<l){
g=l;
d=i;
}
}
printf("%d",d);
return 0;
}
Ⅲ 用C語言編一個程序實現在屏幕上輸出「北京2008奧運會(換行) 然後下一行是 WE ARE READY
void
main()
{
printf("北京2008奧運會");
printf("\n");
/*換行*/
printf("WE
ARE
READY");
getch();
/*程序暫停,按任意鍵退出*/
}
Ⅳ C語言題目 奧運金牌榜 (排序) 題目描述 按時間順序給出奧運會的獲獎情況,根據獲獎情況輸出金牌榜。
#include<stdio.h>
#include<string.h>
intmain()
{
intcount,i,j;
charc[1024][1024],ig[1024],ip[1024];
intp[1024][3];
scanf("%d",&count);
for(i=0;i<count;i++){
scanf("%s%s",ig,ip);
for(j=0;c[j][0]!='