Binary number
Topic
Topic Description:
As we all know, the data stored in the computer is stored in binary form.
One day, Xiaoming learned the C language, he wanted to know a type of unsigned int type of numbers, stored in the computer binary string is what it looks like.
Can you help xiaoming? Also, Xiaoming does not want a binary string in the preceding meaningless 0 string, that is, to remove the leading 0.
Input:
The first line, a number T (t<=1000), represents the number of digits required below.
Next there is the T row, each row has a number n (0<=n<=10^8) that represents the required binary string.
Output:
Outputs a total of t rows. Binary string for each row output.
Sample input:
5
23
535
2624
56275
989835
Sample output:
10111
1000010111
101001000000
1101101111010011
11110001101010001011
AC Code
There is nothing to say, simple mechanism conversion, even large number of division did not investigate!
#include <stdio.h> #include <string.h> #include <stdlib.h>
struct stack {int top;
int data[100];
};
void Convert_to_binary (struct stack *s, unsigned long int d) {s->top = 0;
while (d) {s->data[s->top + +] = d% 2;
D/= 2;
while (s->top) {printf ("%d", s->data[--s->top]);
printf ("\ n");
int main () {int i, n;
unsigned long int D;
struct stack *s = (struct stack*) malloc (sizeof (struct stack));
while (scanf ("%d", &n)!= EOF) {for (i = 0; i < n; i + +) {scanf ("%ld", &d);
if (d!= 0) {convert_to_binary (S, d);
}else {printf ("0\n");
}} return 0; }
/**************************************************************
problem:1473
User:wangzhengyi
Language:c
result:accepted
Time:10 ms
memory:904 kb
****************************************************************/
Two-fork Sort tree
Topic
Topic Description:
Binary sort tree, also known as binary lookup tree. Can be an empty tree, or it can be a non-empty binary tree with the following characteristics:
1. If the left subtree is not empty, all node key values on the left subtree are not greater than the key values of the root node;
2. If the right subtree is not empty, the right subtree all node key values are not small root node key value;
3. The left and right subtree itself is also a binary sort tree.
Now give you n key values are different nodes, you are required to insert an initial empty tree in the two-fork sorting tree, after each insert successful, the corresponding Father node key value, if there is no Father node, then output-1.
Input:
The input contains multiple sets of test data, two rows per set of test data.
The first line, a number N (n<=100), represents the number of nodes to insert.
The second row, N, is a distinct positive integer that represents the key value of the node to be inserted sequentially, and these values do not exceed 10^8.
Output:
Output a total of n rows, each time the node is inserted, the node corresponding to the key value of the parent node.
Sample input:
5
2 5 1 3 4
Sample output:
-1
2
2
5
3
AC Code
No idea, the simplest way to build a binary sort tree
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Btree {struct
Btree *lchild, *rchild;
unsigned long int data;
};
struct btree* create_btree (struct btree *t, unsigned long int d, unsigned long int parent);
int main () {int i, n;
unsigned long int D;
struct Btree *t;
while (scanf ("%d", &n)!= EOF) {t = NULL;
for (i = 0; i < n; i + +) {scanf ("%ld", &d);
t = Create_btree (T, D,-1);
} return 0; } struct btree* create_btree (struct btree *t, unsigned long int d, unsigned long int parent) {if (t = = NU
LL) {t = (struct btree *) malloc (sizeof (struct btree));
T->data = D;
T->lchild = NULL;
T->rchild = NULL;
printf ("%ld\n", parent);
}else if (T->data > D) {t->lchild = Create_btree (T->lchild, D, T->data); }else if (t->datA < D) {t->rchild = Create_btree (T->rchild, D, T->data);
}else {exit (exit_failure);
} return t;
}
/**************************************************************
problem:1467
User:wangzhengyi
Language:c
result:accepted
Time:10 ms
memory:904 kb
****************************************************************/
Matrix Power
Topic
Topic Description:
Given a n*n matrix, the K-power of the matrix is obtained, i.e. the p^k.
Input:
Input contains multiple sets of test data.
The first act of the data is an integer T (0<t<=10) that represents the number of required matrices.
Then there are the T-Group test data, each set of data in the following format:
First line: two integers n (2<=n<=10), K (1<=k<=5), two digits separated by a space, meaning as shown above.
Next there are n rows, n positive integers per row, wherein the J-Integer in line I is the Pij and (0<=pij<=10) of the matrix element in column J of row I of the Matrix. In addition, the data guarantees that the final results will not exceed 10^8.
Output:
For each set of test data, output its results. The format is:
n rows n columns of integers, separated by spaces between lines, note that there should be no extra space after the last number of lines.
Sample input:
3
2 2
9 8
9 3
3 3
4 8 4
9 3 0
3 5 7
5 2
4 0 3 0 1
0 0 5 8 5
8 9 8 5 3
9 6 1 7 8
7 2 5 7 3
Sample output:
153 96
108 81
1216 1248 708
1089 927 504
1161 1151 739
47 29 41 22 16
147 103 73 116 94
162 108 153 168 126
163 67 112 158 122
152 93 93 111 97
AC Code
This is also quite simple, is a matrix multiplication, three for loop can
#include <stdio.h> #include <stdlib.h> #include <string.h> #define LEN int A [LEN]
[LEN], B[len][len], C[len][len];
void Multiplay_matrix ();
int main () {int T, n, K, I, J, D;
scanf ("%d", &t);
while (T-) {//Receive Matrix scanf ("%d%d", &n, &k);
for (i = 0; i < n; i + +) {for (j = 0; J < N; j + +) {scanf ("%d", &d);
A[I][J] = D;
B[I][J] = D;
C[I][J] = D;
}///Matrix power if (k!= 1) {Multiplay_matrix (k, n);
for (i = 0; i < n; i + +) {for (j = 0; J < N; j + +) {if (j = = n-1) {
printf ("%d\n", C[i][j]);
}else {printf ("%d", c[i][j]);
return 0;
} void Multiplay_matrix (int k, int n) {int I, J, h, data;
K--; While (K-) {for (i = 0; i < n; i + +) {for (j = 0; J < N; j + +) {for (h = data = 0; h < n; H + +)
) {data + + b[i][h] * A[h][j];
} C[i][j] = data;
for (i = 0; i < n; i + +) {for (j = 0; J < N; j + +) {B[i][j] = c[i][j];
}
}
}
}
/**************************************************************
problem:1474
User:wangzhengyi
Language:c
result:accepted
Time:10 ms
memory:912 kb
****************************************************************/
IP Packet parsing
Topic
The head length unit is 4 bytes.
Your task is to briefly analyze the headers of several TCP data segments in the input data. For detailed requirements, see the instructions for the input and output section.
Input:
The first behavior is an integer t that represents the number of groups that test the data.
Here are the T rows, each of which is the head portion of a TCP packet, and the byte is separated by a space of 16. Data guarantees that there is only one space between the bytes, and that there are no extra white space characters at the end of the line.
Ensure that the input data is valid.
Output:
For each TCP packet, the following information is exported:
Case #x, X is the serial number of the current test data, starting at 1.
Total length = L bytes,l is the length of the entire IP packet, in units of 1 bytes.
Source = xxx.xxx.xxx.xxx, with dotted decimal point output IP address. There are no IPV6 data groupings in the input data.
Destination = xxx.xxx.xxx.xxx, using dotted decimal to output the source IP address. There are no IPV6 data groupings in the input data.
SOURCE port = Sp,sp is the origin port number.
Destination Port = DP,DP is the target port number.
For each TCP packet, the last output is an extra blank line.
See the sample for a specific format.
Note that in the output information, all spaces, uppercase and lowercase, dot symbols, line wraps are consistent with the sample format, and do not output extra leading 0 before any number, and do not output any unnecessary whitespace characters.
Sample input:
2
7a/5a 0a CD 0a F4 7d-CA-CD f6 b4 D7 AE 1c 9b CF-F2-FF 3d FD D0 00 00 01 0a 7d FB 5e 4e C8
C6 5a E0 CB D0 2e 0a CD 0a f4 ce E1 e9 B9 EE C7 (01) B5 Bayi 8f 00 00, (M) 0a fa c6 cd 8d
Sample output:
Case #1
Total length = bytes
Source = 10.205.10.244
Destination = 125.56.202.9
Source Port = 52726
Destination Port = 80
Case #2
Total length = 198 bytes
Source = 203.208.46.1
Destination = 10.205.10.244
Source Port = 80
Destination Port = 52833
AC Code
Note that the source port number and destination port number should pay attention to the IP head length of the judgment, IHL, other than God horse difficulty
#include <stdio.h> #include <stdlib.h> #include <string.h> #define LEN 1000 int
Change_tint (char *str, int begin, int num) {int i;
Char *temp = (char *) malloc (sizeof (char) * (num + 1));
for (i = 0; i < num i + +) {Temp[i] = Str[begin + i];
} Temp[i] = ';
return Strtol (temp, NULL, 16);
} void Ip_field (char *str, int begin, int num) {int i, flag, IP;
for (i = 0, flag = 1; i < num; i + = 2) {IP = change_tint (str, begin + I, 2);
printf ("%d", IP);
if (flag <= 3) {printf (".");
Flag + +;
printf ("\ n");
int main () {int index, I, J, N, length, IHL;
Char Ipstr[len], Temp[len];
while (scanf ("%d\n", &n)!= EOF) {if (n!= 0) {for (index = 1; index <= n; index + +) {
memset (ipstr, 0, sizeof (IPSTR)); memset (temp, 0, sizeof (temp));
Gets (temp);
Remove space for (i = j = 0, length = strlen (temp); i < length i + +) {if (Temp[i]!= ') {
Ipstr[j + +] = Temp[i];
} Ipstr[j] = ' I ';
The serial number of the current test data printf ("Case #%d\n", index);
Length of the entire IP packet = change_tint (IPSTR, 4, 4);
printf ("Total length =%d bytes\n", length);
Source IP address and destination IP address printf ("Source =");
Ip_field (Ipstr, 24, 8);
printf ("Destination =");
Ip_field (IPSTR, 32, 8);
Source port number and destination port number IHL = Change_tint (IPSTR, 1, 1) * 4 * 2;
printf ("Source Port =%d\n", Change_tint (Ipstr, IHL, 4));
printf ("Destination Port =%d\n", Change_tint (IPSTR, IHL + 4, 4));
printf ("\ n");
}} return 0;
}
/******************************************
problem:1475
User:wangzhengyi
language:c
result:accepted
time:10 Ms
memory:908 KB
**************************************** /