及格成績 描述:10個學生考完期末考試評卷完成後,A老師須要劃及格線,要求以下: (1)及格線是10的倍數;(2)保證至少有60%的學生及格;(3)若是全部的學生都高於60分,則及格線爲60分; 運行時間限制:無限制 內存限制: 無限制 輸入: 輸入10個整數,取值0-100 輸出: 輸出及格線,10的倍數 樣例輸入: 61 51 49 30 20 10 70 80 90 99 樣例輸出: 50node
亮着電燈的盞數 一條長廊裏一次裝有n(1<= n<=65536)盞電燈,從頭至尾編號一、二、三、...n-一、n。每盞電燈由一個拉線開關控制。開始,電燈所有關着。有n個學生從長廊穿過。第一個學生把號碼凡是1的倍數的電燈的開關拉一下,接着第二個學生把號碼凡是2的倍數的電燈的開關拉一下,接着第三個學生把號碼凡是3的倍數的電燈的開關拉一下,如此繼續下去,最後第n個學生把號碼凡是n的倍數的電燈的開關拉一下。n個學生按此規定走完後,長廊裏電燈有幾盞亮着。注:電燈數和學生一致。 運行時間限制:無限制 內存限制: 無限制 輸入: 電燈的數量 輸出: 亮着的電燈數量 樣例輸入: 3 樣例輸出: 1code
地鐵換乘 已知2條地鐵線路,其中A爲環線,B爲東西向線路,線路都是雙向的。通過的站點名分別以下,兩條線交叉的換乘點用T一、T2表示。編寫程序,任意輸入兩個站點名稱,輸出乘坐地鐵最少須要通過的車站數量(含輸入的起點和終點,換乘站點只計算一次) 地鐵線A(環線)通過車站:A1 A2 A3 A4 A5 A6 A7 A8 A9 T1 A10 A11 A12 A13 T2 A14 A15 A16 A17 A18 地鐵線B(直線)通過車站:B1 B2 B3 B4 B5 T1 B6 B7 B8 B9 B10 T2 B11 B12 B13 B14 B15 運行時間限制: 無限制 內存限制: 無限制 輸入: 輸入兩個不一樣的站名 輸出: 輸入最少通過的站數,含輸入的起點和終點,換乘站點只計算一次 樣例輸入: A1 A3 樣例輸出: 3 第一題: <!-- lang: cpp --> #include <stdio.h> #include <stdlib.h> int main() { int score[10]; int pass_score = 0; int tmp = 0; int i = 0,j = 0; int flag = 1; printf("please input the students' score(10)\n"); for(;i< 10; i++) { scanf("%d",&score[i]); if(score[i] < 60) flag = 0; } for(i = 0;i < 10;i++) { for(j = 0;j < 10 - i - 1;j++) { if(score[i] > score[i + j + 1]) { tmp = score[i + j + 1]; score[i + j + 1] = score[i]; score[i] = tmp; } } } printf("the score (desc):\n"); for(i = 0;i < 10;i++) { if(i == 5) printf("\n"); printf("%d\t",score[i]); } printf("\n"); if(flag == 0) pass_score = score[4]/10*10; else pass_score = 60; printf("the pass_score = %d\n",pass_score); return 0; } 第二題: #include <stdio.h> #include <stdlib.h> #include <math.h> int issqrt(int n); int main(){ int light_num = 0; int sum = 0; int i = 0; printf("please input the number of the lights: "); scanf("%d",&light_num); for(i = 1; i < light_num + 1; i++) if(issqrt(i)) sum++; printf("the number of the lights who are on at last is %d\n",sum); return 0; }內存
int issqrt(int n){ int i = 0; for(i = 1; i < n + 1; i++) if(i * i == n) return 1; return 0; }
第三題: #include <stdio.h> #include <stdlib.h> #include <string.h>ci
#define CIR_NUM 20 #define LIN_NUM 17 typedef struct station{ char name[5]; //the name of the station struct station *next; //the pointer that points to the next node struct station *pre; //the pointer that points to the pre node int flag; //the type of the subway int number; }station; void create_circle_list(station **clist_head); void create_line_list(station **llist_head); station *search_station_c(char name[5],station **clist_head); station *search_station_l(char name[5],station **llist_head); int ways_1(int num_1,int num_2); int ways_2(int num_1,int num_2); int main(){ station *clist_hd; //the pointer that point to the first node on the station subway station *llist_hd; //the pointer that point to the first node on the station subway station *phead,*ptail; char query_name_first[5]; char query_name_second[5]; int yes_or_no = 1; int a,b,c,d; int result; phead = ptail = NULL; //create the circle_list; printf("now create the cirlce_list!\n"); create_circle_list(&clist_hd); printf("circle_list is created successfully!\n"); printf("now create the line_list!\n"); create_line_list(&llist_hd); printf("line_list is created successfully!\n"); while(yes_or_no == 1){ printf("please input the names of the stations which you want to query!\n"); scanf("%s%s",query_name_first,query_name_second); phead = (station *)malloc(sizeof(station)); ptail = (station *)malloc(sizeof(station)); if(search_station_c(query_name_first,&clist_hd) != NULL) phead = search_station_c(query_name_first,&clist_hd); if(search_station_l(query_name_first,&llist_hd) != NULL) phead = search_station_l(query_name_first,&llist_hd); if(search_station_c(query_name_second,&clist_hd)) ptail = search_station_c(query_name_second,&clist_hd); if(search_station_l(query_name_second,&llist_hd)) ptail = search_station_l(query_name_second,&llist_hd); if(phead->flag == 1 && ptail->flag == 1){ result = ways_1(phead->number,ptail->number); } else if(phead->flag == 0 && ptail->flag == 0){ result = ways_2(phead->number,ptail->number); } else if(phead->flag ==1 && ptail->flag == 0){ a = ways_1(phead->number,10); b = ways_1(phead->number,15); c = ways_2(ptail->number,6); d = ways_2(ptail->number,12); result = (a + c) > (b + d)? b + d : a + c; result--; } else{ a = ways_2(phead->number,10); b = ways_2(phead->number,15); c = ways_1(ptail->number,6); d = ways_1(ptail->number,12); result = (a + c) > (b + d)? b + d : a + c; result--; } printf("the number of the least stations between %s and %s is %d\n\n",\ phead->name,ptail->name,result); printf("do you want to continue('1' for yes,'0' for no)!\n"); scanf("%d",&yes_or_no); } return 0; } void create_circle_list(station **clist_head){ station *tail = NULL; station *head = NULL; int count = 0; printf("please input the name of the station!(%d)\n",CIR_NUM); head = (station *)malloc(sizeof(station)); scanf("%s",head->name); head->flag = 1; count++; head->number = count; tail = head; while(count < CIR_NUM){ tail->next = (station *)malloc(sizeof(station)); tail->next->pre = tail; tail = tail->next; scanf("%s",tail->name); tail->flag = 1; count++; tail->number = count; } tail->next = head; head->pre = tail; *clist_head = head; } void create_line_list(station **llist_head){ station *head = NULL; station *tail = NULL; int count = 0; printf("please input the name of the station!(%d)\n",LIN_NUM); head = (station *)malloc(sizeof(station)); scanf("%s",head->name); head->flag = 0; count++; head->number = count; tail = head; while(count < LIN_NUM){ tail->next = (station *)malloc(sizeof(station)); tail->next->pre = tail; tail = tail->next; scanf("%s",tail->name); tail->flag = 0; count++; tail->number = count; } tail->next = NULL; *llist_head = head; } station *search_station_c(char name[5],station **clist_head){ station *ptemp; ptemp = NULL; ptemp = *clist_head; int count = 0; while(count < CIR_NUM){ if(strcmp(ptemp->name,name) == 0){ return ptemp; } ptemp = ptemp->next; count++; } return NULL; } station *search_station_l(char name[5],station **llist_head){ station *ptemp; ptemp = NULL; ptemp = *llist_head; int count = 0; while(count < LIN_NUM){ if(strcmp(ptemp->name,name) == 0){ return ptemp; } ptemp = ptemp->next; count++; } return NULL; } int ways_1(int num_1,int num_2){ int result; result = num_1 - num_2; if(result < 0) result = -result; result += 1; if(result > CIR_NUM / 2 + 1) result = CIR_NUM - result + 2; return result; } int ways_2(int num_1,int num_2){ int result; result = num_1- num_2; if(result < 0) result = -result; result += 1; return result; }