Created
October 15, 2013 05:47
-
-
Save seka/6987087 to your computer and use it in GitHub Desktop.
AOJ Volume 100
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> | |
int main(void) | |
{ | |
printf("Hello World\n"); | |
return (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> | |
int main(void) | |
{ | |
int x; | |
scanf("%d", &x); | |
printf("%d\n", x * x * x); | |
return (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> | |
int main(void) | |
{ | |
int height; | |
int width; | |
int s; | |
int r; | |
scanf("%d %d", &height, &width); | |
s = height * width; | |
r = height * 2 + width * 2; | |
printf("%d, %d", s, r); | |
return (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> | |
int main(void) | |
{ | |
int a; | |
int b; | |
scanf("%d %d", &a, &b); | |
if (a == b){ | |
printf("a == b\n"); | |
} | |
else if (a > b){ | |
printf("a > b\n"); | |
} | |
else { | |
printf("a < b\n"); | |
} | |
return (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> | |
#define NUM_LEN (3) | |
int main(void) | |
{ | |
int i, j; | |
int temp; | |
int num[NUM_LEN]; | |
scanf("%d %d %d", &num[0], &num[1], &num[2]); | |
for (i = 0; i < NUM_LEN - 1; i++){ | |
for (j = i + 1; j < NUM_LEN; j++){ | |
if (num[i] > num[j]){ | |
temp = num[i]; | |
num[i] = num[j]; | |
num[j] = temp; | |
} | |
} | |
} | |
for (i = 0; i < NUM_LEN - 1; i++){ | |
printf("%d ", num[i]); | |
} | |
printf("%d\n", num[i]); | |
return (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> | |
#define ROOP (1000) | |
int main(void) | |
{ | |
int i; | |
for (i = 0; i < ROOP; i++){ | |
printf("Hello World\n"); | |
} | |
return (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> | |
int main(void) | |
{ | |
int num; | |
int x; | |
num = 0; | |
while (1){ | |
scanf("%d", &x); | |
if (x == 0){ | |
break; | |
} | |
printf("Case %d: %d\n", num + 1, x); | |
num++; | |
} | |
return (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> | |
int main(void) | |
{ | |
int x, y; | |
while (1){ | |
scanf("%d %d", &x, &y); | |
if (x == 0 && y == 0){ | |
break; | |
} | |
if (x < y){ | |
printf("%d %d\n", x, y); | |
} | |
else { | |
printf("%d %d\n", y, x); | |
} | |
} | |
return (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> | |
int main(void) | |
{ | |
int a, b; | |
int d, r; | |
double f; | |
scanf("%d %d", &a, &b); | |
d = a / b; | |
r = a % b; | |
f = 1.0 * a / b; | |
printf("%d %d %f\n", d, r, f); | |
return (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> | |
#define M_PI (3.141592653589) | |
int main(void) | |
{ | |
double r; | |
double are, circ; | |
scanf("%lf", &r); | |
are = r * r * M_PI; | |
circ = 2 * r * M_PI; | |
printf("%f %f\n", are, circ); | |
return (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> | |
int main(void) | |
{ | |
int x, y; | |
char op; | |
int result; | |
while (1){ | |
scanf("%d %c %d", &x, &op, &y); | |
switch (op){ | |
case '?': | |
return (0); | |
case '+': | |
result = x + y; | |
break; | |
case '-': | |
result = x - y; | |
break; | |
case '*': | |
result = x * y; | |
break; | |
case '/': | |
result = x / y; | |
break; | |
} | |
printf("%d\n", result); | |
} | |
return (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> | |
int main(void) | |
{ | |
int i; | |
int max; | |
int nums[255]; | |
scanf("%d", &max); | |
for (i = 0; i < max; i++){ | |
scanf("%d" , &nums[i]); | |
} | |
for (i = max - 1; 0 <= i; i--){ | |
printf("%d", nums[i]); | |
if (i) { | |
printf(" "); | |
} | |
} | |
printf("\n"); | |
return (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> | |
int main(void) | |
{ | |
int i, j; | |
int width, height; | |
while (1){ | |
scanf("%d %d", &height, &width); | |
if (height == 0 & width == 0){ | |
break; | |
} | |
for (i = 0; i < height; i++){ | |
for (j = 0; j < width; j++){ | |
printf("#"); | |
} | |
printf("\n"); | |
} | |
printf("\n"); | |
} | |
return (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> | |
int main(void) | |
{ | |
int i, j; | |
int width, height; | |
while (1){ | |
scanf("%d %d", &height, &width); | |
if (width == 0){ | |
break; | |
} | |
for (i = 0; i < height; i++){ | |
for (j = 0; j < width; j++){ | |
if ((i == 0 || i == height - 1) || (j == 0 || j == width - 1)){ | |
printf("#"); | |
} | |
else { | |
printf("."); | |
} | |
} | |
printf("\n"); | |
} | |
printf("\n"); | |
} | |
return (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> | |
int main(void) | |
{ | |
int i, j; | |
int width, height; | |
while (1){ | |
scanf("%d %d", &height, &width); | |
if (height == 0 && width == 0){ | |
break; | |
} | |
for (i = 0; i < height; i++){ | |
for (j = 0; j < width; j++){ | |
if ((i + j) % 2 == 0){ | |
printf("#"); | |
} | |
else { | |
printf("."); | |
} | |
} | |
printf("\n"); | |
} | |
printf("\n"); | |
} | |
return (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> | |
#define KIND (4) | |
#define MAX_NUM (13) | |
#define ON (1) | |
#define OFF (0) | |
#define S (0) | |
#define H (1) | |
#define C (2) | |
#define D (3) | |
int main(void) | |
{ | |
int i, j, n; | |
int card[KIND][MAX_NUM]; | |
int num; | |
char kind; | |
scanf("%d", &n); | |
for (i = 0; i < KIND; i++){ | |
for (j = 0; j < MAX_NUM; j++){ | |
card[i][j] = OFF; | |
} | |
} | |
for (i = 0; i < n; i++){ | |
scanf("%*c%c %d", &kind, &num); | |
if (kind == 'S'){ | |
card[S][num - 1] = ON; | |
} | |
else if (kind == 'H'){ | |
card[H][num - 1] = ON; | |
} | |
else if (kind == 'D'){ | |
card[D][num - 1] = ON; | |
} | |
else { | |
card[C][num - 1] = ON; | |
} | |
} | |
for (i = 0; i < KIND; i++){ | |
for (j = 0; j < MAX_NUM; j++){ | |
if (card[i][j] == OFF){ | |
if (i == S){ | |
printf("S "); | |
} | |
else if (i == H){ | |
printf("H "); | |
} | |
else if (i == C){ | |
printf("C "); | |
} | |
else { | |
printf("D "); | |
} | |
printf("%d\n", j + 1); | |
} | |
} | |
} | |
return (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> | |
int main(void) | |
{ | |
int m, f, r; | |
int sum; | |
char result; | |
while (1){ | |
scanf("%d %d %d", &m, &f, &r); | |
if (m == -1 && f == -1 && r == -1){ | |
break; | |
} | |
sum = m + f; | |
if (sum >= 80){ | |
result = 'A'; | |
} | |
else if (sum >= 65 && sum < 80){ | |
result = 'B'; | |
} | |
else if (sum >= 50 && sum < 65){ | |
result = 'C'; | |
} | |
else { | |
if (r >= 50){ | |
result = 'C'; | |
} | |
else { | |
result = 'D'; | |
} | |
} | |
if (m == -1 || f == -1 || sum < 30){ | |
result = 'F'; | |
} | |
printf("%c\n", result); | |
} | |
return (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> | |
int main(void) | |
{ | |
int i, j, k; | |
int n, x; | |
int count; | |
while (1){ | |
scanf("%d %d", &n, &x); | |
if (n == 0 && x == 0){ | |
break; | |
} | |
count = 0; | |
for (i = 1; i <= n; i++){ | |
for (j = i + 1; j <= n; j++){ | |
for (k = j + 1; k <= n; k++){ | |
if (i + j + k == x){ | |
count++; | |
} | |
} | |
} | |
} | |
printf("%d\n", count); | |
} | |
return (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> | |
int main(void) | |
{ | |
char ch; | |
while (1){ | |
scanf("%c", &ch); | |
if ('a' <= ch && ch <= 'z'){ | |
printf("%c", ch - 0x20); | |
} | |
else if ('A' <= ch && ch <= 'Z'){ | |
printf("%c", ch + 0x20); | |
} | |
else { | |
printf("%c", ch); | |
} | |
if (ch == '\n'){ | |
break; | |
} | |
} | |
return (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 <string.h> | |
#define DIGIT (1001) | |
int main(void) | |
{ | |
char num[DIGIT]; | |
int i; | |
int sum; | |
while (1){ | |
scanf("%s", num); | |
if (num[0] == '0'){ | |
break; | |
} | |
sum = 0; | |
for (i = 0; i < strlen(num); i++){ | |
sum += num[i] - '0'; | |
} | |
printf("%d\n", sum); | |
} | |
return (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> | |
#define LENGTH (100) | |
#define CHAR (26) | |
int main(void) | |
{ | |
int i; | |
char ch; | |
char alphabet[CHAR]; | |
for (i = 0; i < CHAR; i++){ | |
alphabet[i] = 0; | |
} | |
while (scanf("%c", &ch) != EOF){ | |
if ('A' <= ch && ch <= 'Z'){ | |
alphabet[ch - 'A']++; | |
} | |
if ('a' <= ch && ch <= 'z'){ | |
alphabet[ch - 'a']++; | |
} | |
} | |
for (i = 0; i < CHAR; i++){ | |
printf("%c : %d\n", 'a' + i, alphabet[i]); | |
} | |
return (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 <string.h> | |
#define NUM (1000) | |
#define LEN (100) | |
int main(void) | |
{ | |
int i; | |
int j; | |
int count; | |
char str[NUM][LEN]; | |
char temp[LEN]; | |
scanf("%d", &count); | |
for (i = 0; i < count; i++){ | |
scanf("%s", str[i]); | |
} | |
for (i = 0; i < count - 1; i++){ | |
for (j = count - 1; i <= j; j--){ | |
if (strcmp(str[j], str[j - 1]) < 0){ | |
strcpy(temp, str[j]); | |
strcpy(str[j], str[j - 1]); | |
strcpy(str[j - 1], temp); | |
} | |
} | |
} | |
printf("%s\n", str[0]); | |
return (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 <string.h> | |
#define LEN (1024) | |
#define END ("END_OF_TEXT") | |
int main(void) | |
{ | |
int i; | |
int count; | |
char text[LEN]; | |
char str[LEN]; | |
scanf("%s", str); | |
for (i = 0; i < strlen(str); i++){ | |
if ('a' <= str[i] && str[i] <= 'z'){ | |
str[i] -= 0x20; | |
} | |
} | |
count = 0; | |
while (1){ | |
scanf("%s", text); | |
if (strcmp(text, END) == 0){ | |
break; | |
} | |
for (i = 0; i < strlen(text); i++){ | |
if ('a' <= text[i] && text[i] <= 'z'){ | |
text[i] -= 0x20; | |
} | |
} | |
if (strcmp(str, text) == 0){ | |
count++; | |
} | |
} | |
printf("%d\n", count); | |
return (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 <string.h> | |
#define LEN (256) | |
#define END ('-') | |
int main(void) | |
{ | |
int i; | |
int j; | |
int k; | |
int num; | |
int shuffle; | |
char card[LEN]; | |
char temp[LEN]; | |
while (1){ | |
scanf("%s", card); | |
if ((card[0] == '-') && (card[1] == '\0')){ | |
break; | |
} | |
scanf("%d", &shuffle); | |
for (i = 0; i < shuffle; i++){ | |
scanf("%d", &num); | |
k = 0; | |
for (j = num; j < strlen(card); j++){ | |
temp[k++] = card[j]; | |
} | |
for (j = 0; j < num; j++){ | |
temp[k++] = card[j]; | |
} | |
temp[k] = '\0'; | |
strcpy(card, temp); | |
} | |
printf("%s\n", card); | |
} | |
return (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 <math.h> | |
int main(void) | |
{ | |
double x1, x2; | |
double y1, y2; | |
double dist; | |
scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2); | |
dist = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)); | |
printf("%f\n", dist); | |
return (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 <math.h> | |
int main(void) | |
{ | |
int a; | |
int b; | |
double c; | |
double angle; | |
double height; | |
double space; | |
double around; | |
scanf("%d %d %lf", &a, &b, &angle); | |
c = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(angle * M_PI / 180.0); | |
c = sqrt(c); | |
space = a * b * sin(angle * M_PI / 180.0) / 2.0; | |
around = a + b + c; | |
height = space * 2 / a; | |
printf("%f\n", space); | |
printf("%f\n", around); | |
printf("%f\n", height); | |
return (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 <math.h> | |
#define LEN (1000) | |
int main(void) | |
{ | |
int i; | |
int j; | |
int n; | |
int sum; | |
int s[LEN]; | |
double ave; | |
double dispersion; | |
while (1){ | |
scanf("%d", &n); | |
if (n == 0){ | |
break; | |
} | |
for (i = 0; i < n; i++){ | |
scanf("%d", &s[i]); | |
} | |
sum = 0; | |
for (i = 0; i < n; i++){ | |
sum += s[i]; | |
} | |
ave = 1.0 * sum / n; | |
dispersion = 0; | |
for (i = 0; i < n; i++){ | |
dispersion += pow(s[i] - ave, 2); | |
} | |
dispersion /= n; | |
dispersion = sqrt(dispersion); | |
printf("%f\n", dispersion); | |
} | |
return (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 <string.h> | |
#define MAX_TURN (1000) | |
#define MAX_LEN (100) | |
#define TARO (0) | |
#define HANAKO (1) | |
int main(void) | |
{ | |
int i; | |
int turn; | |
int points[2]; | |
char taro_card[MAX_LEN]; | |
char hanako_card[MAX_LEN]; | |
scanf("%d", &turn); | |
points[TARO] = 0; | |
points[HANAKO] = 0; | |
for (i = 0; i < turn; i++){ | |
scanf("%s", taro_card); | |
scanf("%s", hanako_card); | |
if (strcmp(taro_card, hanako_card) > 0){ | |
points[TARO] += 3; | |
} | |
else if (strcmp(taro_card, hanako_card) < 0){ | |
points[HANAKO] += 3; | |
} | |
else { | |
points[TARO]++; | |
points[HANAKO]++; | |
} | |
} | |
printf("%d %d\n", points[TARO], points[HANAKO]); | |
return (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> | |
#define MAX (1000) | |
int main(void) | |
{ | |
int i; | |
int j; | |
int tmp; | |
int n; | |
int numbers[MAX]; | |
scanf("%d", &n); | |
for (i = 0; i < n; i++){ | |
scanf("%d", &numbers[i]); | |
} | |
for (i = 0; i < n - 1; i++){ | |
for (j = n - 1; i < j; j--){ | |
if (numbers[j] < numbers[j - 1]){ | |
tmp = numbers[j]; | |
numbers[j] = numbers[j - 1]; | |
numbers[j - 1] = tmp; | |
} | |
} | |
} | |
printf("%d", numbers[0]); | |
for (i = 1; i < n; i++){ | |
printf(" %d", numbers[i]); | |
} | |
printf("\n"); | |
return (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> | |
#define MAX (1000000) | |
void qsort(int *numbers, int left, int right); | |
int main(void) | |
{ | |
int i; | |
int n; | |
int numbers[MAX]; | |
scanf("%d", &n); | |
for (i = 0; i < n; i++){ | |
scanf("%d", &numbers[i]); | |
} | |
qsort(numbers, 0, n - 1); | |
printf("%d", numbers[0]); | |
for (i = 1; i < n; i++){ | |
printf(" %d", numbers[i]); | |
} | |
printf("\n"); | |
return (0); | |
} | |
void qsort(int *numbers, int left, int right) | |
{ | |
int i = left; | |
int j = right; | |
int tmp; | |
int pivot = numbers[(left + right) / 2]; | |
while (1){ | |
while (numbers[i] < pivot){ | |
i++; | |
} | |
while (pivot < numbers[j]){ | |
j--; | |
} | |
if (i >= j){ | |
break; | |
} | |
tmp = numbers[i]; | |
numbers[i] = numbers[j]; | |
numbers[j] = tmp; | |
i++; | |
j--; | |
} | |
if (left < i - 1){ | |
qsort(numbers, left, i - 1); | |
} | |
if (j + 1 < right){ | |
qsort(numbers, j + 1, right); | |
} | |
} |
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> | |
#define MAX (100) | |
int main(void) | |
{ | |
int i; | |
int j; | |
int n; | |
int q; | |
int s_sets[MAX]; | |
int q_sets[MAX]; | |
int repetition; | |
int tmp; | |
scanf("%d", &n); | |
for (i = 0; i < n; i++){ | |
scanf("%d", &s_sets[i]); | |
} | |
scanf("%d", &q); | |
for (i = 0; i < q; i++){ | |
scanf("%d", &q_sets[i]); | |
} | |
tmp = -1; | |
repetition = 0; | |
for (i = 0; i < q; i++){ | |
for (j = 0; j < n; j++){ | |
if (s_sets[j] == tmp){ | |
continue; | |
} | |
else if (q_sets[i] == s_sets[j]){ | |
repetition++; | |
tmp = q_sets[i]; | |
} | |
} | |
} | |
printf("%d\n", repetition); | |
return (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> | |
#define S_MAX (100000) | |
#define Q_MAX (50000) | |
void qsort(int *numbers, int left, int right); | |
int main(void) | |
{ | |
int i; | |
int j; | |
int n; | |
int q; | |
int s_sets[S_MAX]; | |
int q_sets[Q_MAX]; | |
int repetition; | |
int tmp; | |
scanf("%d", &n); | |
for (i = 0; i < n; i++){ | |
scanf("%d", &s_sets[i]); | |
} | |
scanf("%d", &q); | |
for (i = 0; i < q; i++){ | |
scanf("%d", &q_sets[i]); | |
} | |
qsort(s_sets, 0, n - 1); | |
tmp = -1; | |
repetition = 0; | |
for (i = 0; i < q; i++){ | |
for (j = 0; j < n; j++){ | |
if (q_sets[i] < s_sets[j]){ | |
break; | |
} | |
if (tmp == s_sets[j]){ | |
continue; | |
} | |
else if (q_sets[i] == s_sets[j]){ | |
repetition++; | |
tmp = q_sets[i]; | |
} | |
} | |
} | |
printf("%d\n", repetition); | |
return (0); | |
} | |
void qsort(int *numbers, int left, int right) | |
{ | |
int i = left; | |
int j = right; | |
int tmp; | |
int pivot = numbers[(left + right) / 2]; | |
while (1){ | |
while (numbers[i] < pivot){ | |
i++; | |
} | |
while (pivot < numbers[j]){ | |
j--; | |
} | |
if (i >= j){ | |
break; | |
} | |
tmp = numbers[i]; | |
numbers[i] = numbers[j]; | |
numbers[j] = tmp; | |
i++; | |
j--; | |
} | |
if (left < i - 1){ | |
qsort(numbers, left, i - 1); | |
} | |
if (j + 1 < right){ | |
qsort(numbers, j + 1, right); | |
} | |
} |
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 <string.h> | |
#define COMMAND_LEN (10) | |
#define BLOCK_LEN (1001) | |
#define PUSH ("push") | |
#define POP ("pop") | |
#define QUIT ("quit") | |
int main(void) | |
{ | |
int i; | |
int k; | |
char command[COMMAND_LEN]; | |
char c; | |
char blocks[BLOCK_LEN]; | |
char order[BLOCK_LEN]; | |
k = 0; | |
while (1){ | |
scanf("%s", command); | |
if (strcmp(QUIT, command) == 0){ | |
break; | |
} | |
if (strcmp(PUSH, command) == 0){ | |
scanf(" %c", &c); | |
blocks[strlen(blocks)] = c; | |
blocks[strlen(blocks) + 1] = '\0'; | |
} | |
else if (strcmp(POP, command) == 0){ | |
order[k] = blocks[strlen(blocks) - 1]; | |
order[k + 1] = '\0'; | |
k++; | |
blocks[strlen(blocks) - 1] = '\0'; | |
} | |
} | |
for (i = 0; i < strlen(order); i++){ | |
printf("%c\n", order[i]); | |
} | |
return (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 <string.h> | |
#define COMMAND_LEN (10) | |
#define BLOCK_ROW (100) | |
#define BLOCK_LEN (1001) | |
#define PUSH ("push") | |
#define POP ("pop") | |
#define MOVE ("move") | |
#define QUIT ("quit") | |
int main(void) | |
{ | |
int i; | |
int k; | |
char command[COMMAND_LEN]; | |
char c; | |
int num; | |
int target; | |
char blocks[BLOCK_ROW][BLOCK_LEN]; | |
char order[BLOCK_LEN]; | |
scanf("%d", &num); | |
k = 0; | |
while (1){ | |
scanf("%s", command); | |
if (strcmp(QUIT, command) == 0){ | |
break; | |
} | |
if (strcmp(PUSH, command) == 0){ | |
scanf("%d", &num); | |
scanf(" %c", &c); | |
num--; | |
blocks[num][strlen(blocks[num])] = c; | |
blocks[num][strlen(blocks[num])] = '\0'; | |
} | |
else if (strcmp(POP, command) == 0){ | |
scanf("%d", &num); | |
num--; | |
order[k] = blocks[num][strlen(blocks[num]) - 1]; | |
order[k + 1] = '\0'; | |
k++; | |
blocks[num][strlen(blocks[num]) - 1] = '\0'; | |
} | |
else if (strcmp(MOVE, command) == 0){ | |
scanf("%d", &num); | |
scanf("%d", &target); | |
num--; | |
target--; | |
blocks[target][strlen(blocks[target])] = blocks[num][strlen(blocks[num]) - 1]; | |
blocks[target][strlen(blocks[target])] = '\0'; | |
blocks[num][strlen(blocks[num]) - 1] = '\0'; | |
} | |
} | |
for (i = 0; i < strlen(order); i++){ | |
printf("%c\n", order[i]); | |
} | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment