Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created August 17, 2012 02:02
Show Gist options
  • Save iporsut/3375246 to your computer and use it in GitHub Desktop.
Save iporsut/3375246 to your computer and use it in GitHub Desktop.
ZOJ 1073 : Round and Round We Go
#include <stdio.h>
#include <string.h>
char digit[61];
char result[61];
int multiply_by(int n, int len) {
int i, carry = 0, v;
for (i = len-1; i >= 0; --i) {
v = (digit[i]-'0')*n + carry;
result[i] = (v % 10) + '0';
carry = v / 10;
}
return carry;
}
int main() {
int i, j, k, len, count;
while(scanf("%s", digit) != EOF) {
count = 0;
len = strlen(digit);
strcpy(result,digit);
for (i = 1; i <= len; i++) {
if (! multiply_by(i, len)) {
for (j = 0; j < len; j++) {
if (result[j] == digit[0]) {
for (k = 0; k < len; k++) {
if (digit[k] != result[(k+j) % len])
break;
}
if (k == len) {
count++;
break;
}
}
}
}
}
if (count != len)
printf("%s is not cyclic\n", digit);
else
printf("%s is cyclic\n", digit);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment