- 论坛徽章:
- 7
|
回复 19# bmne
shishi martii:
martii.c
- # include <stdio.h>
- # include <stdlib.h>
- # include <string.h>
- # include <ctype.h>
- typedef char kar;
- typedef char *str;
- typedef unsigned Int;
- typedef int my;
- str* gimme (str);
- void die ();
- void martii (str*, int, int);
- int main (int para, str *vektor) {
- if (para < 3) die (vektor[0]);
- str *corak = gimme (vektor[1]);
- int alkaa = atoi (vektor[2]);
- int pituus = para == 4 ? atoi (vektor[3]) : alkaa;
- martii (corak, alkaa, pituus);
- } /* main */
- // ______________________SUB______________________
- void martii (str *corak, int alkaa, int pituus) {
- static int lengde[256];
- int haba = 0;
- while (corak[haba++] != NULL)
- lengde[haba - 1] = strlen (corak[haba - 1]);
- haba -= 1;
- int maks = haba;
- Int totaal = 1;
- for (my woorde = 1; woorde <= pituus; woorde++) {
- totaal *= haba;
- if (woorde < alkaa) continue;
- Int oinez = totaal;
- int hasita = woorde - 1;
- int oke[woorde];
- memset (oke, 0, woorde * sizeof(int));
- static kar sosei[256] = { 0 };
- int posisie[woorde + 1];
- posisie[0] = 0;
- int eniro = 0;
- while (oinez--) {
- for (my i = eniro; i < woorde; i++) {
- int aantal = lengde[oke[i]];
- memcpy (sosei + posisie[i], corak[oke[i]], aantal);
- posisie[i + 1] = posisie[i] + aantal;
- }
- sosei[posisie[woorde]] = 0;
- puts (sosei);
- for (eniro = hasita; eniro >= 0; eniro--) {
- if (++oke[eniro] < maks) break;
- else oke[eniro] = 0;
- }
- }
- }
- while (*corak) free (*corak++);
- } /* martii */
- str * gimme (str skedar) {
- static str elfen[256] = { 0 };
- kar laina[36];
- FILE *fil = fopen (skedar, "r");
- int posisie = 0;
- while (fgets (laina, 36, fil) != NULL) {
- int lengde = strlen (laina);
- int hale = laina[lengde - 2] == '\r' ? 2 : 1;
- laina[lengde - hale] = 0;
- elfen[posisie++] = strdup (laina);
- }
- fclose (fil);
- return elfen;
- }
- void die (str zelf) {
- printf ("use:\n");
- printf ("%s file n\t\t[ n >= 1 ]\n", zelf);
- printf ("%s file n1 n2\t[ n1 < n2 ]\n", zelf);
- exit (1);
- }
复制代码
|
|