/* *****************************************************
 *
 *
 *
 * **************************************************** */
int next_label_block(int *L, int n, int m)
{
    // s is for starting location
    int s, l, i, j, block;
    int next=0;

    // Initialize the begining
    block=n/m;
    s=0;
    for(l=0; l<block; l++) {
        // Find the permutation within one block
        next=next_permu(L+s, m);
        if(next) {
            // Resetting of the previous to the original
            for(i=0; i<l; i++) {
                for(j=0; j<m; j++) {
                    L[i*m+j]=j;
                }
            }
            return 1;
        }
        s+=m;
    }

    // We couldn't find the next permutation
    return 0;
}
int main(int argc, char *argv[])
{
	FILE *fp;
	char s[5];

	fp = fopen(*++argv, "r");
	while (fscanf(fp, "%hhd %hhd %hhd %hhd %hhd", &s[0], &s[1], &s[2], &s[3], &s[4]) != EOF) {
		bool f = false;
		qsort(s, 5, 1, ccmp);
		f = gives42(s);
		while (!f && next_permu(s))
			f = gives42(s);
		puts(f ? "YES" : "NO");
	}
	return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
	FILE *fp;
	char line[32];

	fp = fopen(*++argv, "r");
	while (fgets(line, 31, fp) != 0) {
		int strl = strlen(line)-1;
		char *c, *w =  malloc(strl*sizeof(char));
		c = strncpy(w, line, strl);
		qsort(c, strl, sizeof(char), ccmp);
		printf("%s", c);
		while (next_permu(c, strl))
			printf(",%s", c);
		printf("\n");
		free(w);
	}
	return 0;
}
Example #4
0
int main(int argc, char *argv[]) {
	FILE *fp;
	unsigned long strl;
	char line[32];

	if (argc != 2) {
		printf("Usage: %s [FILE]\n", argv[0]);
		return 1;
	}
	fp = fopen(*++argv, "r");
	while (fgets(line, 31, fp) != 0) {
		strl = strlen(line);
		strl -= line[strl - 1] == '\n';
		char *c, *w = malloc(strl);
		c = strncpy(w, line, strl);
		qsort(c, strl, 1, ccmp);
		printf("%s", c);
		while (next_permu(c, strl))
			printf(",%s", c);
		printf("\n");
		free(w);
	}
	return 0;
}