Advertisement
k_vychodilova

Křizovka_C

Feb 20th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #define VELIKOST 8000000
  6.  
  7. // const int VELIKOST 100000;
  8.  
  9. int main(int argc, char** argv) {
  10.     static char* pole[VELIKOST]; // static umožní větší velikost, je uložený v paměti globálních proměnných
  11.  
  12.     FILE *seznam= fopen("CZ.txt","r");
  13.     srand(time(NULL));
  14.            
  15.     char buffer[256];
  16.     int i = 0;
  17.     while(fscanf(seznam,"%255s", buffer)!=EOF && i < VELIKOST) {
  18.         int delka = strlen(buffer);
  19.         if(delka > 1) {
  20.             char* novy = malloc(delka+1);
  21.             strcpy(novy, buffer);
  22.             pole[i++] = novy;
  23.         }
  24.         if ( (i & (4*65536-1)) == 0)
  25.             printf("Precten %d. radek\n", i);
  26.     }
  27.  
  28.    /* int N = i;
  29.     for(i = 0; i < N; i++)
  30.         puts(pole[i]);
  31.         */
  32.     int nahodne;
  33.     int j;
  34.     char *pozice;
  35.     int delka;
  36.     char *tajenka = "oka";
  37.     char *slova[strlen(tajenka)];
  38.     //int pomocna=0;
  39.     int max_delka=0;
  40.     printf("\n");
  41.     printf("TAJENKA JE :\n\n");
  42.     for(j=0;j<strlen(tajenka);j++)  //projit slova
  43.     {
  44.         do{
  45.         nahodne = rand() % 7000000;
  46.         pozice = strchr( pole[nahodne], tajenka[j]);  //pokud nenajde pozici=null
  47.         //pomocna=pomocna+1;
  48.         }while(pozice == NULL);  
  49.        
  50.         slova[j]=pole[nahodne];
  51.         delka = pozice -pole[nahodne];
  52.         //delka = strlen(pozice);
  53.         //printf("%d\n",delka);      //delka o kolik se má posunout
  54.         if(delka>max_delka)
  55.         {
  56.             max_delka=delka;
  57.                        
  58.             }
  59.        
  60.     }
  61.     for(int k=0;k<strlen(tajenka);k++)
  62.     {
  63.         pozice = strchr( slova[k], tajenka[k]);
  64.         delka = pozice -slova[k];
  65.         for(int m=0;m<max_delka-delka;m++)
  66.         {
  67.             printf(" ");
  68.            
  69.            
  70.             }
  71.         printf("%s\n",slova[k]);
  72.                
  73.                 }
  74.    
  75.     getchar();
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement