Skip to content

Instantly share code, notes, and snippets.

@kunishi
Created July 2, 2012 07:13
Show Gist options
  • Select an option

  • Save kunishi/3031635 to your computer and use it in GitHub Desktop.

Select an option

Save kunishi/3031635 to your computer and use it in GitHub Desktop.
ACM International Collegiate Programming Contest, Japan Domestic, 2006, Problem B
#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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment