-
-
Save kunishi/8702262 to your computer and use it in GitHub Desktop.
ICPC2006
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define TRUE 1 | |
#define FALSE 0 | |
int main(int argc, char *argv[]) | |
{ | |
FILE *in; | |
int a, d, n; | |
int number; | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s file\n", argv[0]); | |
exit(1); | |
} | |
if ((in = fopen(argv[1], "r")) == NULL) { | |
fprintf(stderr, "cannot open %s\n", argv[0]); | |
} | |
while (1) { | |
fscanf(in, "%d %d %d", &a, &d, &n); | |
if (a == 0 && d == 0 && n == 0) { | |
break; | |
} | |
number = a; | |
while (n != 0) { | |
if (isPrime(number) == TRUE) { | |
if (n == 1) { | |
printf("%d\n", number); | |
break; | |
} | |
n --; | |
} | |
number += d; | |
} | |
} | |
} | |
int isPrime(int x) | |
{ | |
int i; | |
if (x == 1) { | |
return FALSE; | |
} | |
for (i = 2; i < x; i ++) { | |
if (x % i == 0) { | |
return FALSE; | |
} | |
} | |
return TRUE; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
367 186 151 | |
179 10 203 | |
271 37 39 | |
103 230 1 | |
27 104 185 | |
253 50 85 | |
1 1 1 | |
9075 337 210 | |
307 24 79 | |
331 221 177 | |
259 170 40 | |
269 58 102 | |
0 0 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void perm(char *, char *, int); | |
int main(int argc, char *argv[]) | |
{ | |
FILE *in; | |
int data_num; | |
int i, j, k; | |
char orig[72]; | |
char changed[72]; | |
char pattern[72][72 * 8]; | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s file\n", argv[0]); | |
exit(1); | |
} | |
if ((in = fopen(argv[1], "r")) == NULL) { | |
fprintf(stderr, "cannot open %s\n", argv[1]); | |
exit(1); | |
} | |
fscanf(in, "%d", &data_num); | |
for (i = 0; i < data_num; i ++) { | |
fscanf(in, "%s", orig); | |
for (j = 1; j < strlen(orig); j ++) { | |
perm(orig, changed, j); | |
memset(changed, 0, 72); | |
} | |
/* | |
strcpy(orig, pattern[0]); | |
} | |
*/ | |
} | |
} | |
void perm(char *s, char *t, int pos) | |
{ | |
int i; | |
int len = strlen(s); | |
for (i = 0; i <= len - pos; i ++) { | |
*(t + i) = *(s + pos + i); | |
} | |
for (i = 0; i < pos; i ++) { | |
*(t + (len - pos) + i) = *(s + i); | |
} | |
printf("%s\n", t); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 | |
aa | |
abba | |
abcd | |
abcde |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char *argv[]) | |
{ | |
FILE *in; | |
char stack[100]; | |
char str[100]; | |
int n; | |
int c; | |
int top; | |
int bottom; | |
int i; | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s file\n", argv[0]); | |
exit(1); | |
} | |
if ((in = fopen(argv[1], "r")) == NULL) { | |
fprintf(stderr, "cannot open %s\n", argv[1]); | |
exit(1); | |
} | |
n = 0; top = 0; i = 0; | |
while ((c = fgetc(in)) != EOF) { | |
if (c >= '0' && c <= '9') { | |
n = n * 10 + c - '0'; | |
continue; | |
} | |
if (c >= 'A' && c <= 'Z') { | |
if (n != 0) { | |
stack[top ++] = n; | |
} | |
str[i ++] = c; | |
continue; | |
} | |
if (c == '(') { | |
stack[top ++] = n; | |
continue; | |
} | |
if (c == ')') { | |
} | |
if (c == '\n') { | |
top = 0; | |
n = 0; | |
continue; | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54322 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment