显示原始代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
typedef struct Node {
int data;
struct Node* next;
} List;
int Adddata(List* H);
int Insert(List* H, int temp);
int yihup(List* H);
int main() {
int n;
scanf("%d", &n);
List* H = (List*)malloc(sizeof(List));
H->next = NULL;
H->data = -1;
for (int i = 0; i < n; i++) {
int temp1, temp2;
scanf("%d", &temp1);
if (temp1 == 1) {
Adddata(H);
} else if (temp1 == 2) {
scanf("%d", &temp2);
Insert(H, temp2);
}
yihup(H);
}
return 0;
}
int Adddata(List* H) {
List* p = H;
while (p) {
p->data++;
p = p->next;
}
return 0;
}
int Insert(List* H, int temp) {
List* p = H;
while (p->next != NULL) {
p = p->next;
}
List* kNode = (List*)malloc(sizeof(List));
kNode->data = temp;
kNode->next = NULL;
p->next = kNode;
return 0;
}
int yihup(List* H) {
int num1, num2, sum = 0;
List* p = H->next;
if (p == NULL) {
printf("0\n");
return 0;
}
if (p->next == NULL) {
printf("%d\n", p->data);
return 0;
}
int data1 = p->data;
while (p->next) {
int data2 = p->next->data;
int flag = 1;
while (data1 != 0 || data2 != 0) {
num1 = data1 % 2;
num2 = data2 % 2;
data1 /= 2;
data2 /= 2;
if (num1 != num2) {
sum = sum + flag;
}
flag *= 2;
}
p = p->next;
data1 = sum;
}
printf("%d\n", sum);
return 0;
}