Created
October 8, 2011 08:14
-
-
Save hiromu/1272009 to your computer and use it in GitHub Desktop.
EPOCH Qualifier
This file contains 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 compare(const void *a, const void *b) | |
{ | |
return (*(int *)b - *(int *)a); | |
} | |
int main(void) | |
{ | |
int i = 0, j = -1, k = 0, n; | |
int *a, *b; | |
scanf("%d", &n); | |
a = malloc(sizeof(int) * n); | |
b = malloc(sizeof(int) * n); | |
for(i = 0; i < n; i++) | |
scanf("%d", &a[i]); | |
qsort(a, n, sizeof(int), compare); | |
for(i = 0; i < n; i++) { | |
if(j == -1) | |
if(a[i] == a[i + 1]) | |
j = a[i]; | |
else | |
b[k++] = a[i]; | |
else | |
if(j - 1 < k) | |
break; | |
else if(a[i] != a[i + 1]) | |
b[k++] = a[i]; | |
while(a[i] == a[i + 1]) | |
i++; | |
} | |
if(j != -1 && j - 1 < k) | |
printf("%d\n", b[j - 1]); | |
else | |
printf("%d\n", b[k - 1]); | |
return 0; | |
} |
This file contains 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> | |
int main(void) | |
{ | |
int i, j, k, l, m, n; | |
long long int point = 0; | |
char a[256], b[256]; | |
scanf("%d%s", &n, b); | |
for(i = 0; i < n - 1; i++) { | |
strcpy(a, b); | |
scanf("%s", b); | |
j = strlen(a); | |
k = strlen(b); | |
l = 0; | |
if(j == k) { | |
for(m = 0; m < j; m++) { | |
if(a[m] != b[m]) { | |
l++; | |
if(l > 1) | |
break; | |
} | |
} | |
if(l == 0) | |
point *= 2; | |
else if(l == 1) | |
point += 2; | |
else | |
point = 0; | |
} else if(j == k - 1) { | |
for(m = 0; m < k; m++) { | |
if(a[l] == b[m]) | |
l++; | |
if(m - l > 1) | |
break; | |
} | |
if(m - l == 1) | |
point++; | |
else | |
point = 0; | |
} else if(j == k + 1) { | |
for(m = 0; m < j; m++) { | |
if(a[m] == b[l]) | |
l++; | |
if(m - l > 1) | |
break; | |
} | |
if(m - l == 1) | |
point--; | |
else | |
point = 0; | |
} else { | |
point = 0; | |
} | |
} | |
printf("%lld\n", point); | |
return 0; | |
} |
This file contains 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> | |
int checksum(const char *nums, int plus, int equal, int last) | |
{ | |
int a = 1, b = 1, c = 1, d = 0, i = 0, x, y, z; | |
while(a || b || c) { | |
if(!a || i >= plus) { | |
a = 0; | |
x = 0; | |
} else { | |
x = *(nums + plus - i - 1) - '0'; | |
} | |
if(!b || i >= equal - plus) { | |
b = 0; | |
y = 0; | |
} else { | |
y = *(nums + equal - i - 1) - '0'; | |
} | |
if(!c || i >= last - equal) { | |
c = 0; | |
z = 0; | |
} else { | |
z = *(nums + last - i - 1) - '0'; | |
} | |
if((d + x + y) % 10 == z) { | |
d = (d + x + y) / 10; | |
i++; | |
} else { | |
return 0; | |
} | |
} | |
return 1; | |
} | |
int main(void) | |
{ | |
char num[1000]; | |
int comp, equal, firstpos, last, n, plus, pluspos, res = 0; | |
scanf("%d", &n); | |
while(n--) { | |
scanf("%s", num); | |
last = strlen(num); | |
firstpos=0; | |
while(num[firstpos] == '0') | |
firstpos++; | |
comp = 1; | |
for(plus = 1; plus - firstpos <= (last - firstpos) / 2 && comp; plus++) { | |
if(plus - firstpos > (last - plus) / 2) { | |
equal = last - (plus - firstpos); | |
} else { | |
pluspos = plus; | |
while(num[pluspos] == '0') | |
pluspos++; | |
if(plus - firstpos > (last - pluspos) / 2) | |
equal = last - (plus -firstpos); | |
else | |
equal = pluspos + (last - pluspos) / 2; | |
} | |
do{ | |
if(checksum(num, plus, equal, last) || checksum(num, plus, equal-1, last)) { | |
comp = 0; | |
res++; | |
break; | |
} | |
equal -= 2; | |
} while(num[equal] == '0'); | |
} | |
} | |
printf("%d\n", res); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment