Suppose program name is sled and myfile.txt is a text file.
After the "myfile.txt" has been read in the memory and the data structure built, the program
will enter interactive mode by prompting '>' to let user enter commands. The program should
print '>' for prompting after the execution of each command.
> l
This is the first line.
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(void) { | |
int T; | |
scanf("%d\n", &T); | |
const char* map = "OIZEASGTBP"; | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
const char* month[13] = {"", "January", "February", "March", "April", "May", | |
"June", "July", "August", "September", "October", "November", "December"}; | |
int is_leap_year(int year) { | |
if (year % 400 == 0) | |
return 1; |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main() { | |
int N; | |
while (scanf("%d", &N)) { | |
if (N == 0) break; | |
int row_sum[N]; |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <math.h> | |
long long J[31268+1]; | |
char S[145234+1]; | |
int s_idx; | |
void init() { |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int primes[168] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, | |
59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, | |
139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, | |
229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, | |
317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, | |
421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, |
#組合
如何找出 C(N, M) (C N 取 M)的所有組合,我們的工具有 next_permutation
,但它只能用來做排列,所以我們需要一點小技巧。
考慮資料是 [4, 3, 6, 2, 1]
。我們想找出 C(5, 2) 的所有組合,我們可以設一個長度為 5
的零一陣列,其中前三項為 0
,後二項為 1
:
[0, 0, 0, 1, 1]
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdbool.h> | |
#include <time.h> | |
#include <unistd.h> // for sleep() | |
int min(const int a, const int b) { | |
return ((a > b) ? b : a); | |
} |
Write a program to calculate the damage of a bomb explosion. We assume that when a bomb explodes, it will create an N by N square explosion around its center. In addition, an N by N explosion will create four smaller N/2 by N/2 explosions around its boundary. The four new explosions will be next to the original explosion, and align with the original explosion at the midpoints of the four sides. Please refer to the following figure for an illustration. This "chain-reaction" explosion will stop when the size of explosion is no more than 2. Explosion causes damage. If a location (x, y) is within or at the boundary of an N by N explosion, it will sustain N damage. If a location (x, y) is within multiple explosions,