#include<stdio.h>#include<string.h>structstudent{int a;char name[20];};structstudent1{int b;char name1[20];};intmain(){structstudent s1[50];structstudent1 s2[50];structstudent1 s3[50];int i, n, j =0, t =0, c, d;scanf("%d",&n);for(i =0; i < n; i++){scanf("%d %s",&s1[i].a, s1[i].name);}for(i =0; i < n; i++){if(s1[i].a ==1){
s2[j].b = i;strcpy(s2[j].name1, s1[i].name);
j++;}if(s1[i].a ==0){
s3[t].b = i;strcpy(s3[t].name1, s1[i].name);
t++;}}
c = n /2-1, d = n /2-1;
j =0, t =0;for(i =0; i < n /2; i++){if(s3[j].b < s2[t].b){printf("%s %s\n", s3[j].name1, s2[c].name1);
j++;
c--;}else{printf("%s %s\n", s2[t].name1, s3[d].name1);
t++;
d--;}}return0;}
7-2 考试座位号
#include<stdio.h>structstudent{char num[17];int s;int k;};intmain(){int n =0;scanf("%d",&n);structstudent stu[1000]={0};for(int i =0; i < n; i++){scanf("%s %d %d", stu[i].num,&stu[i].s,&stu[i].k);}int m =0,ret;scanf("%d",&m);for(int i =0; i < m; i++){scanf("%d",&ret);int j=0;for(j =0; j < n; j++){if(ret == stu[j].s){printf("%s %d\n", stu[j].num, stu[j].k);}}}return0;}
7-3 新键表输出
#include<stdio.h>#include<stdlib.h>// 定义链表节点结构体typedefstructListNode{int val;structListNode* next;} ListNode;// 定义头节点指针
ListNode*createList(){
ListNode* head =NULL;int num;while(1){scanf("%d",&num);if(num ==-1){break;}
ListNode* newNode =(ListNode*)malloc(sizeof(ListNode));
newNode->val = num;
newNode->next =NULL;if(head ==NULL){
head = newNode;}else{
ListNode* cur = head;while(cur->next !=NULL){
cur = cur->next;}
cur->next = newNode;}}return head;}// 遍历链表,将奇数值节点插入新链表
ListNode*createNewList(ListNode* head){
ListNode* newHead =NULL;
ListNode* cur = head;while(cur !=NULL){if(cur->val %2!=0){
ListNode* newNode =(ListNode*)malloc(sizeof(ListNode));
newNode->val = cur->val;
newNode->next =NULL;if(newHead ==NULL){
newHead = newNode;}else{
ListNode* temp = newHead;while(temp->next !=NULL){
temp = temp->next;}
temp->next = newNode;}}
cur = cur->next;}return newHead;}// 打印链表voidprintList(ListNode* head){
ListNode* cur = head;printf("%d", cur->val);
cur = cur->next;while(cur !=NULL){printf(" %d", cur->val);
cur = cur->next;}printf("\n");}intmain(){// 创建链表
ListNode* head =createList();// 创建新链表
ListNode* newHead =createNewList(head);// 打印新链表printList(newHead);return0;}