fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. #define MIN 4
  9.  
  10. int leia_rows;
  11. int leia_col;
  12.  
  13. int difficulty_troopers(int rows, int col, int diff);
  14. int difficulty_obstacles(int rows, int col, int diff);
  15. void start_table(char **p,int rows,int col);
  16. void random_stuff(char **p, int rows, int col, int diff);
  17. int play(char **p, char **v, int rows, int col);
  18. void ask_help(char **p, char **v,int rows, int col);
  19. void change_obstacle(char **p, char **v, int rows, int col);
  20. void move(char **p, char **v, int rows, int col, int vert, int horiz);
  21. void leia_visibility(char **p,int rows,int col);
  22.  
  23.  
  24. int main(){
  25. int diff;
  26. int rows,col,i,j;
  27. char **arr = NULL;
  28. char **arr1 = NULL;
  29. leia_row = -1;
  30. leia_col = -1;
  31.  
  32. printf("\nWelcome to Princess's Leia spaceship!\n");
  33. printf("Can you find R2D2, while being chased by the Republic ?\n\n");
  34.  
  35. do{
  36. printf("Pick rows size: ");
  37. scanf("%d",&rows);
  38.  
  39. printf("Pick columns size: ");
  40. scanf("%d",&col);
  41. }while(rows <1 || col < 1);
  42.  
  43. do{
  44. printf("Pick number for difficulty:\n");
  45. printf("1.Easy\n2.Medium\n3.Hard\n4.Impossible\n");
  46. scanf("%d",&diff);
  47. }while(diff < 1 || diff > 4);
  48.  
  49.  
  50. //while(rows*col > MIN){
  51. arr = (char**)malloc(rows * sizeof(char*));
  52. if(arr == NULL){
  53. printf("FAILED MEMORY ALLOCATION 1\n");
  54. return -1;
  55. }
  56. else{
  57. for(i = 0; i < rows; i++){
  58. arr[i] = (char*)malloc(col * (sizeof(char)));
  59. if(arr[i] == NULL){
  60. printf("FAILED MEMORY ALLOCATION 2\n");
  61. return -1;
  62. }
  63. }
  64. }
  65.  
  66. /* for(i = 0; i < rows; i++){
  67.   for(j = 0; j < col; j++){
  68.   arr[i][j] = '#';
  69.   }
  70.   } */
  71. // }
  72.  
  73.  
  74. srand(time(NULL));
  75. leia_rows = rand() % rows;
  76. leia_col = rand() % col;
  77. p[leia_rows][leia_col] = 'L';
  78.  
  79. switch(diff){
  80. case 1:
  81. random_stuff(arr, rows, col, diff);
  82. // play(arr, arr1, rows,col);
  83. break;
  84. case 2:
  85. random_stuff(arr, rows, col, diff);
  86. //play(arr, arr1, rows,col);
  87. break;
  88. case 3:
  89. random_stuff(arr, rows, col, diff);
  90. //play(arr, arr1, rows,col);
  91. break;
  92. case 4:
  93. random_stuff(arr, rows, col, diff);
  94. //play(arr, arr1, rows,col);
  95. break;
  96. }
  97.  
  98.  
  99.  
  100. return 0;
  101. }
  102.  
  103.  
  104. int difficulty_troopers(int rows, int col, int diff){
  105.  
  106. if(diff == 1){
  107. return round(rows * col * (0.02)); // stroggylopoiei
  108. }
  109. else if(diff == 2){
  110. return round(rows * col * (0.05));
  111. }
  112. else if(diff == 3){
  113. return round(rows * col * (0.1));
  114. }
  115. else if(diff == 4){
  116. return round(rows * col * (0.15));
  117. }
  118. else{
  119. return 0;
  120. }
  121. }
  122.  
  123. int difficulty_obstacles(int rows, int col, int diff){
  124.  
  125. if(diff == 1){
  126. return round(rows * col * (0.13));
  127. }
  128. else if(diff == 2){
  129. return round(rows * col * (0.1));
  130. }
  131. else if(diff == 3){
  132. return round(rows * col * (0.05));
  133. }
  134. else if(diff == 4){
  135. return 0;
  136. }
  137. else{
  138. return 0;
  139. }
  140. }
  141.  
  142.  
  143. void start_table(char **p, int rows, int col){ // EKTIPOSI
  144. int i,j;
  145. int x,y;
  146. char c = 'A';
  147.  
  148. printf(" %c",c);
  149. for(j = 0; j < col - 1; j++){
  150. printf(" %c", c + 1);
  151. c+=1;
  152. }
  153. printf("\n");
  154.  
  155. printf("---");
  156. for(j = 0; j < col - 1; j++){
  157. printf("-----");
  158. }
  159. printf("---\n");
  160.  
  161. for(i = 0; i < rows; i++){
  162. printf(" %d |",i + 1);
  163. for(j = 0; j < col; j++){
  164. if(p[i][j] == 'L' || p[i][j] == 'V' || p[i][j] == 'X'){
  165. printf(" %c ", p[i][j]);
  166. }
  167. else{
  168. printf(" %c ", '#');
  169. }
  170. printf("\n");
  171. }
  172. }
  173.  
  174.  
  175. void random_stuff(char **p, int rows, int col, int diff){
  176. int i,j;
  177. int o = 0;
  178. int t = 0;
  179. int characters = 0;
  180.  
  181. srand(time(NULL));
  182.  
  183. // TOPOTHETISI OBSTACLES KAI TROOPERS
  184.  
  185. while(t < difficulty_troopers(rows, col, diff) ){
  186. i = rand() % rows;
  187. j = rand() % col;
  188.  
  189. if((i >= 0) && (j >= 0) && (i < rows) && (j < col)){
  190. if((i != leia_rows || j != leia_col) && p[i][j] != 'X' && p[i][j] != '@'){
  191. p[i][j] = '@';
  192. t++;
  193. }
  194. }
  195. else{
  196. t--;
  197. }
  198. }
  199.  
  200. while(o < difficulty_obstacles(rows, col, diff)){
  201. i = rand() % rows;
  202. j = rand() % col;
  203.  
  204. if((i >= 0) && (j >= 0) && (i < rows) && (j < col)){
  205. if((i != leia_rows || j != leia_col) && p[i][j] != '@' && p[i][j] != 'X'){
  206. p[i][j] = 'X';
  207. o++;
  208. }
  209. }
  210. else{
  211. o--;
  212. }
  213. }
  214.  
  215. i = rand() % rows;
  216. j = rand() % col;
  217.  
  218. if(p[i][j] != '@' && p[i][j] != 'X' && p[i][j] != 'L'){
  219. p[i][j] = 'V';
  220. }
  221.  
  222. i = rand() % rows;
  223. j = rand() % col;
  224.  
  225. if(p[i][j] != '@' && p[i][j] != 'X' && p[i][j] != 'L' && p[i][j] != 'V'){
  226. p[i][j] = 'R';
  227. }
  228.  
  229. for(i = 0; i < rows; i++){
  230. p[i][leia_col] = '.';
  231. }
  232.  
  233. for(j = 0; j < col; j++){}
  234. p[leia_rows][j] = '.';
  235. }
  236.  
  237. p[leia_rows][leia_col] = 'L';
  238.  
  239. start_table(p, rows, col);
  240. }
  241.  
  242.  
  243. /* int play(char **p,char **v, int rows, int col){
  244.   char move[10];
  245.   char choice[10];
  246.   int i;
  247.   int a = 0;
  248.   int x = 0, y = 0;
  249.  
  250.   printf("\nMake your move(s): ");
  251.   scanf("%s",choice);
  252.  
  253.   for(int i = 0; i < strlen(choice); i++){
  254.   choice[i] = tolower(choice[i]);
  255.   }
  256.  
  257.  
  258.   while(a != 1){
  259.   if(strcmp(choice, "x") == 0){
  260.   return 1;
  261.   a = 1; // kanei exit...as poume
  262.   }
  263.   else if(strcmp(choice, "h") == 0){
  264.   ask_help(p, v, rows, col); // ftiaksimo sto kalesma
  265.   }
  266.   else{
  267.   for(int i = 0; i < strlen(choice); i++){
  268.   if(i == 2){
  269.   if(choice[2] == '>'){
  270.   change_obstacle(p, v, rows, col);
  271.   }
  272.   }
  273.  
  274.   if(choice[i] == 'u'){
  275.   move(p, v, rows, col, x - 1, y);
  276.   }
  277.   else if(choice[i] == 'd'){
  278.   move(p, v, rows, col, x + 1, y);
  279.   }
  280.   else if(choice[i] == 'l'){
  281.   move(p, v, rows, col, x, y - 1);
  282.   }
  283.   else if(choice[i] == 'r'){
  284.   move(p, v, rows, col, x, y + 1);
  285.   }
  286.   }
  287.   }
  288.   }
  289.  
  290. } */
  291.  
  292.  
  293.  
  294.  
  295. unsigned long golay(unsigned long cw)
  296. /* This function calculates [23,12] Golay codewords.
  297.   The format of the returned longint is
  298.   [checkbits(11),data(12)]. */
  299. {
  300. int i;
  301. unsigned long c;
  302. cw&=0xfffl;
  303. c=cw; /* save original codeword */
  304. for (i=1; i<=12; i++) /* examine each data bit */
  305. {
  306. if (cw & 1) /* test data bit */
  307. cw^=POLY; /* XOR polynomial */
  308. cw>>=1; /* shift intermediate result */
  309. }
  310. return((cw<<12)|c); /* assemble codeword */
  311. }
  312.  
  313. /* ====================================================== */
  314.  
  315. int parity(unsigned long cw)
  316. /* This function checks the overall parity of codeword cw.
  317.   If parity is even, 0 is returned, else 1. */
  318. {
  319. unsigned char p;
  320.  
  321. /* XOR the bytes of the codeword */
  322. p=*(unsigned char*)&cw;
  323. p^=*((unsigned char*)&cw+1);
  324. p^=*((unsigned char*)&cw+2);
  325.  
  326. /* XOR the halves of the intermediate result */
  327. p=p ^ (p>>4);
  328. p=p ^ (p>>2);
  329. p=p ^ (p>>1);
  330.  
  331. /* return the parity result */
  332. return(p & 1);
  333. }
  334.  
  335. /* ====================================================== */
  336.  
  337. unsigned long syndrome(unsigned long cw)
  338. /* This function calculates and returns the syndrome
  339.   of a [23,12] Golay codeword. */
  340. {
  341. int i;
  342. cw&=0x7fffffl;
  343. for (i=1; i<=12; i++) /* examine each data bit */
  344. {
  345. if (cw & 1) /* test data bit */
  346. cw^=POLY; /* XOR polynomial */
  347. cw>>=1; /* shift intermediate result */
  348. }
  349. return(cw<<12); /* value pairs with upper bits of cw */
  350. }
  351.  
  352. /* ====================================================== */
  353.  
  354. int weight(unsigned long cw)
  355. /* This function calculates the weight of
  356.   23 bit codeword cw. */
  357. {
  358. int bits,k;
  359.  
  360. /* nibble weight table */
  361. const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
  362.  
  363. bits=0; /* bit counter */
  364. k=0;
  365. /* do all bits, six nibbles max */
  366. while ((k<6) && (cw))
  367. {
  368. bits=bits+wgt[cw & 0xf];
  369. cw>>=4;
  370. k++;
  371. }
  372.  
  373. return(bits);
  374. }
  375.  
  376. /* ====================================================== */
  377.  
  378. unsigned long rotate_left(unsigned long cw, int n)
  379. /* This function rotates 23 bit codeword cw left by n bits. */
  380. {
  381. int i;
  382.  
  383. if (n != 0)
  384. {
  385. for (i=1; i<=n; i++)
  386. {
  387. if ((cw & 0x400000l) != 0)
  388. cw=(cw << 1) | 1;
  389. else
  390. cw<<=1;
  391. }
  392. }
  393.  
  394. return(cw & 0x7fffffl);
  395. }
  396.  
  397. /* ====================================================== */
  398.  
  399. unsigned long rotate_right(unsigned long cw, int n)
  400. /* This function rotates 23 bit codeword cw right by n bits. */
  401. {
  402. int i;
  403.  
  404. if (n != 0)
  405. {
  406. for (i=1; i<=n; i++)
  407. {
  408. if ((cw & 1) != 0)
  409. cw=(cw >> 1) | 0x400000l;
  410. else
  411. cw>>=1;
  412. }
  413. }
  414.  
  415. return(cw & 0x7fffffl);
  416. }
  417.  
  418. /* ====================================================== */
  419.  
  420. unsigned long correct(unsigned long cw, int *errs)
  421. /* This function corrects Golay [23,12] codeword cw, returning the
  422.   corrected codeword. This function will produce the corrected codeword
  423.   for three or fewer errors. It will produce some other valid Golay
  424.   codeword for four or more errors, possibly not the intended
  425.   one. *errs is set to the number of bit errors corrected. */
  426. {
  427. unsigned char
  428. w; /* current syndrome limit weight, 2 or 3 */
  429. unsigned long
  430. mask; /* mask for bit flipping */
  431. int
  432. i,j; /* index */
  433. unsigned long
  434. s, /* calculated syndrome */
  435. cwsaver; /* saves initial value of cw */
  436.  
  437. cwsaver=cw; /* save */
  438. *errs=0;
  439. w=3; /* initial syndrome weight threshold */
  440. j=-1; /* -1 = no trial bit flipping on first pass */
  441. mask=1;
  442. while (j<23) /* flip each trial bit */
  443. {
  444. if (j != -1) /* toggle a trial bit */
  445. {
  446. if (j>0) /* restore last trial bit */
  447. {
  448. cw=cwsaver ^ mask;
  449. mask+=mask; /* point to next bit */
  450. }
  451. cw=cwsaver ^ mask; /* flip next trial bit */
  452. w=2; /* lower the threshold while bit diddling */
  453. }
  454.  
  455. s=syndrome(cw); /* look for errors */
  456. if (s) /* errors exist */
  457. {
  458. for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
  459. {
  460. if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
  461. {
  462. cw=cw ^ s; /* remove errors */
  463. cw=rotate_right(cw,i); /* unrotate data */
  464. return(s=cw);
  465. }
  466. else
  467. {
  468. cw=rotate_left(cw,1); /* rotate to next pattern */
  469. s=syndrome(cw); /* calc new syndrome */
  470. }
  471. }
  472. j++; /* toggle next trial bit */
  473. }
  474. else
  475. return(cw); /* return corrected codeword */
  476. }
  477.  
  478. return(cwsaver); /* return original if no corrections */
  479. } /* correct */
  480.  
  481. /* ====================================================== */
  482.  
  483. int decode(int correct_mode, int *errs, unsigned long *cw)
  484. /* This function decodes codeword *cw in one of two modes. If correct_mode
  485.   is nonzero, error correction is attempted, with *errs set to the number of
  486.   bits corrected, and returning 0 if no errors exist, or 1 if parity errors
  487.   exist. If correct_mode is zero, error detection is performed on *cw,
  488.   returning 0 if no errors exist, 1 if an overall parity error exists, and
  489.   2 if a codeword error exists. */
  490. {
  491. unsigned long parity_bit;
  492.  
  493. if (correct_mode) /* correct errors */
  494. {
  495. parity_bit=*cw & 0x800000l; /* save parity bit */
  496. *cw&=~0x800000l; /* remove parity bit for correction */
  497.  
  498. *cw=correct(*cw, errs); /* correct up to three bits */
  499. *cw|=parity_bit; /* restore parity bit */
  500.  
  501. /* check for 4 bit errors */
  502. if (parity(*cw)) /* odd parity is an error */
  503. return(1);
  504. return(0); /* no errors */
  505. }
  506. else /* detect errors only */
  507. {
  508. *errs=0;
  509. if (parity(*cw)) /* odd parity is an error */
  510. {
  511. *errs=1;
  512. return(1);
  513. }
  514. if (syndrome(*cw))
  515. {
  516. *errs=1;
  517. return(2);
  518. }
  519. else
  520. return(0); /* no errors */
  521. }
  522. } /* decode */
  523.  
  524. /* ====================================================== */
  525.  
  526. void golay_test(void)
  527. /* This function tests the Golay routines for detection and correction
  528.   of various patterns of error_limit bit errors. The error_mask cycles
  529.   over all possible values, and error_limit selects the maximum number
  530.   of induced errors. */
  531. {
  532. unsigned long
  533. error_mask, /* bitwise mask for inducing errors */
  534. trashed_codeword, /* the codeword for trial correction */
  535. virgin_codeword; /* the original codeword without errors */
  536. unsigned char
  537. pass=1, /* assume test passes */
  538. error_limit=3; /* select number of induced bit errors here */
  539. int
  540. error_count; /* receives number of errors corrected */
  541.  
  542. virgin_codeword=golay(0x555); /* make a test codeword */
  543. if (parity(virgin_codeword))
  544. virgin_codeword^=0x800000l;
  545. for (error_mask=0; error_mask<0x800000l; error_mask++)
  546. {
  547. /* filter the mask for the selected number of bit errors */
  548. if (weight(error_mask) <= error_limit) /* you can make this faster! */
  549. {
  550. trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
  551.  
  552. decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
  553.  
  554. if (trashed_codeword ^ virgin_codeword)
  555. {
  556. printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
  557. weight(error_mask),error_mask);
  558. pass=0;
  559. }
  560.  
  561. if (kbhit()) /* look for user input */
  562. {
  563. if (getch() == 27) return; /* escape exits */
  564.  
  565. /* other key prints status */
  566. printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
  567. }
  568. }
  569. }
  570. printf("Golay test %s!\n",pass?"PASSED":"FAILED");
  571. }
  572.  
  573. /* ====================================================== */
  574.  
  575. void main(int argument_count, char *argument[])
  576. {
  577. int i,j;
  578. unsigned long l,g;
  579. const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
  580. " where DATA is the data to be encoded, codeword to be corrected,\n"
  581. " or codeword to be checked for errors. DATA is hexadecimal.\n\n"
  582. "Examples:\n\n"
  583. " G 555 E encodes information value 555 and prints a codeword\n"
  584. " G ABC123 C corrects codeword ABC123\n"
  585. " G ABC123 V checks codeword ABC123 for errors\n"
  586. " G ABC123 T tests routines, ABC123 is a dummy parameter\n\n";
  587.  
  588. if (argument_count != 3)
  589. {
  590. printf(errmsg);
  591. exit(0);
  592. }
  593.  
  594. if (sscanf(argument[1],"%lx",&l) != 1)
  595. {
  596. printf(errmsg);
  597. exit(0);
  598. }
  599.  
  600. switch (toupper(*argument[2]))
  601. {
  602. case 'E': /* encode */
  603. l&=0xfff;
  604. l=golay(l);
  605. if (parity(l)) l^=0x800000l;
  606. printf("Codeword = %lX\n",l);
  607. break;
  608.  
  609. case 'V': /* verify */
  610. if (decode(0,&i,&l))
  611. printf("Codeword %lX is not a Golay codeword.\n",l);
  612. else
  613. printf("Codeword %lX is a Golay codeword.\n",l);
  614. break;
  615.  
  616. case 'C': /* correct */
  617. g=l; /* save initial codeword */
  618. j=decode(1,&i,&l);
  619. if ((j) && (i))
  620. printf("Codeword %lX had %d bits corrected,\n"
  621. "resulting in codeword %lX with a parity error.\n",g,i,l);
  622. else
  623. if ((j == 0) && (i))
  624. printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
  625. else
  626. if ((j) && (i == 0))
  627. printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
  628. else
  629. if ((j == 0) && (i == 0))
  630. printf("Codeword %lX does not require correction.\n",g);
  631. break;
  632.  
  633. case 'T': /* test */
  634. printf("Press SPACE for status, ESC to exit test...\n");
  635. golay_test();
  636. break;
  637.  
  638. default:
  639. printf(errmsg);
  640. exit(0);
  641. }
  642. }
  643.  
  644. /* end of G.C */
  645.  
  646.  
  647. import java.util.*;
  648. import java.lang.*;
  649. import java.io.*;
  650.  
  651. /* Name of the class has to be "Main" only if the class is public. */
  652. class Ideone
  653. {
  654. public static void main (String[] args) throws java.lang.Exception
  655. {
  656. // your code goes here
  657. }
  658. }
Success #stdin #stdout 0.03s 25884KB
stdin
Standard input is empty
stdout
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <ctype.h>

#define MIN 4

int leia_rows;
int leia_col;

int difficulty_troopers(int rows, int col, int diff);
int difficulty_obstacles(int rows, int col, int diff);
void start_table(char **p,int rows,int col);
void random_stuff(char **p, int rows, int col, int diff);
int play(char **p, char **v, int rows, int col);
void ask_help(char **p, char **v,int rows, int col);
void change_obstacle(char **p, char **v, int rows, int col);
void move(char **p, char **v, int rows, int col, int vert, int horiz);
void leia_visibility(char **p,int rows,int col);


int main(){
    int diff;
    int rows,col,i,j;
    char **arr = NULL;
    char **arr1 = NULL;
    leia_row = -1;
    leia_col = -1;

    printf("\nWelcome to Princess's Leia spaceship!\n");
    printf("Can you find R2D2, while being chased by the Republic ?\n\n");

    do{
        printf("Pick rows size: ");
        scanf("%d",&rows);

        printf("Pick columns size: ");
        scanf("%d",&col);
    }while(rows <1 || col < 1);

    do{
        printf("Pick number for difficulty:\n");
        printf("1.Easy\n2.Medium\n3.Hard\n4.Impossible\n");
        scanf("%d",&diff);
    }while(diff < 1 || diff > 4);


    //while(rows*col > MIN){
        arr = (char**)malloc(rows * sizeof(char*));
        if(arr == NULL){
            printf("FAILED MEMORY ALLOCATION 1\n");
            return -1;
        }
        else{
            for(i = 0; i < rows; i++){
                arr[i] = (char*)malloc(col * (sizeof(char)));
                if(arr[i] == NULL){
                    printf("FAILED MEMORY ALLOCATION 2\n");
                    return -1;
                }
            }
        }

    /*    for(i = 0; i < rows; i++){
            for(j = 0; j < col; j++){
                arr[i][j] = '#';
            }
        }  */
  //  }


    srand(time(NULL));
    leia_rows = rand() % rows;
    leia_col = rand() % col;
    p[leia_rows][leia_col] = 'L';

    switch(diff){
        case 1:
            random_stuff(arr, rows, col, diff);
           // play(arr, arr1, rows,col);
            break;
        case 2:
            random_stuff(arr, rows, col, diff);
            //play(arr, arr1, rows,col);
            break;
        case 3:
            random_stuff(arr, rows, col, diff);
            //play(arr, arr1, rows,col);
            break;
        case 4:
            random_stuff(arr, rows, col, diff);
            //play(arr, arr1, rows,col);
            break;
    }



    return 0;
}


int difficulty_troopers(int rows, int col, int diff){

    if(diff == 1){
        return round(rows * col * (0.02));    // stroggylopoiei
    }
    else if(diff == 2){
        return round(rows * col * (0.05));
    }
    else if(diff == 3){
        return round(rows * col * (0.1));
    }
    else if(diff == 4){
        return round(rows * col * (0.15));
    }
    else{
        return 0;
    }
}

int difficulty_obstacles(int rows, int col, int diff){

    if(diff == 1){
        return round(rows * col * (0.13));
    }
    else if(diff == 2){
        return round(rows * col * (0.1));
    }
    else if(diff == 3){
        return round(rows * col * (0.05));
    }
    else if(diff == 4){
        return 0;
    }
    else{
        return 0;
    }
}


void start_table(char **p, int rows, int col){   // EKTIPOSI
    int i,j;
    int x,y;
    char c = 'A';

    printf("     %c",c);
    for(j = 0; j < col - 1; j++){
        printf("  %c", c + 1);
        c+=1;
    }
    printf("\n");

    printf("---");
    for(j = 0; j < col - 1; j++){
	  	printf("-----");
	}
    printf("---\n");

    for(i = 0; i < rows; i++){
        printf(" %d |",i + 1);
        for(j = 0; j < col; j++){
            if(p[i][j] == 'L' || p[i][j] == 'V' || p[i][j] == 'X'){
                printf(" %c ", p[i][j]);
            }
            else{
                printf(" %c ", '#');
            }
        printf("\n");
    }
}


void random_stuff(char **p, int rows, int col, int diff){
    int i,j;
    int o = 0;
    int t = 0;
    int characters = 0;

    srand(time(NULL));

    // TOPOTHETISI OBSTACLES KAI TROOPERS

    while(t < difficulty_troopers(rows, col, diff) ){
        i = rand() % rows;
        j = rand() % col;

        if((i >= 0) && (j >= 0) && (i < rows) && (j < col)){
            if((i != leia_rows || j != leia_col) && p[i][j] != 'X' && p[i][j] != '@'){
                p[i][j] = '@';
                t++;
            }
        }
        else{
            t--;
        }
    }

    while(o < difficulty_obstacles(rows, col, diff)){
        i = rand() % rows;
        j = rand() % col;

        if((i >= 0) && (j >= 0) && (i < rows) && (j < col)){
            if((i != leia_rows || j != leia_col) && p[i][j] != '@' && p[i][j] != 'X'){
                p[i][j] = 'X';
                o++;
            }
        }
        else{
            o--;
        }
    }

    i = rand() % rows;
    j = rand() % col;

    if(p[i][j] != '@' && p[i][j] != 'X' && p[i][j] != 'L'){
        p[i][j] = 'V';
    }

    i = rand() % rows;
    j = rand() % col;

    if(p[i][j] != '@' && p[i][j] != 'X' && p[i][j] != 'L' && p[i][j] != 'V'){
            p[i][j] = 'R';
    }

    for(i = 0; i < rows; i++){
        p[i][leia_col] = '.';
    }

    for(j = 0; j < col; j++){}
        p[leia_rows][j] = '.';
    }

    p[leia_rows][leia_col] = 'L';

    start_table(p, rows, col);
}


/* int play(char **p,char **v, int rows, int col){
    char move[10];
    char choice[10];
    int i;
    int a = 0;
    int x = 0, y = 0;

    printf("\nMake your move(s): ");
    scanf("%s",choice);

    for(int i = 0; i < strlen(choice); i++){
        choice[i] = tolower(choice[i]);
    }


    while(a != 1){
        if(strcmp(choice, "x") == 0){
            return 1;
            a = 1;   // kanei exit...as poume
        }
        else if(strcmp(choice, "h") == 0){
            ask_help(p, v, rows, col);   // ftiaksimo sto kalesma
        }
        else{
            for(int i = 0; i < strlen(choice); i++){
                if(i == 2){
                    if(choice[2] == '>'){
                        change_obstacle(p, v, rows, col);
                    }
                }

                if(choice[i] == 'u'){
                    move(p, v, rows, col, x - 1, y);
                }
                else if(choice[i] == 'd'){
                    move(p, v, rows, col, x + 1, y);
                }
                else if(choice[i] == 'l'){
                    move(p, v, rows, col, x, y - 1);
                }
                else if(choice[i] == 'r'){
                    move(p, v, rows, col, x, y + 1);
                }
            }
        }
    }

} */




    unsigned long golay(unsigned long cw)
    /* This function calculates [23,12] Golay codewords.
      The format of the returned longint is
      [checkbits(11),data(12)]. */
    {
      int i;
      unsigned long c;
      cw&=0xfffl;
      c=cw; /* save original codeword */
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return((cw<<12)|c);    /* assemble codeword */
    }
    
    /* ====================================================== */
    
    int parity(unsigned long cw)
    /* This function checks the overall parity of codeword cw.
      If parity is even, 0 is returned, else 1. */
    {
      unsigned char p;
    
      /* XOR the bytes of the codeword */
      p=*(unsigned char*)&cw;
      p^=*((unsigned char*)&cw+1);
      p^=*((unsigned char*)&cw+2);
    
      /* XOR the halves of the intermediate result */
      p=p ^ (p>>4);
      p=p ^ (p>>2);
      p=p ^ (p>>1);
    
      /* return the parity result */
      return(p & 1);
    }
    
    /* ====================================================== */
    
    unsigned long syndrome(unsigned long cw)
    /* This function calculates and returns the syndrome
      of a [23,12] Golay codeword. */
    {
      int i;
      cw&=0x7fffffl;
      for (i=1; i<=12; i++)  /* examine each data bit */
        {
          if (cw & 1)        /* test data bit */
            cw^=POLY;        /* XOR polynomial */
          cw>>=1;            /* shift intermediate result */
        }
      return(cw<<12);        /* value pairs with upper bits of cw */
    }
    
    /* ====================================================== */
    
    int weight(unsigned long cw)
    /* This function calculates the weight of
      23 bit codeword cw. */
    {
      int bits,k;
    
      /* nibble weight table */
      const char wgt[16] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
    
      bits=0; /* bit counter */
      k=0;
      /* do all bits, six nibbles max */
      while ((k<6) && (cw))
        {
          bits=bits+wgt[cw & 0xf];
          cw>>=4;
          k++;
        }
    
      return(bits);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_left(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw left by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 0x400000l) != 0)
                cw=(cw << 1) | 1;
              else
                cw<<=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long rotate_right(unsigned long cw, int n)
    /* This function rotates 23 bit codeword cw right by n bits. */
    {
      int i;
    
      if (n != 0)
        {
          for (i=1; i<=n; i++)
            {
              if ((cw & 1) != 0)
                cw=(cw >> 1) | 0x400000l;
              else
                cw>>=1;
            }
        }
    
      return(cw & 0x7fffffl);
    }
    
    /* ====================================================== */
    
    unsigned long correct(unsigned long cw, int *errs)
    /* This function corrects Golay [23,12] codeword cw, returning the
      corrected codeword. This function will produce the corrected codeword
      for three or fewer errors. It will produce some other valid Golay
      codeword for four or more errors, possibly not the intended
      one. *errs is set to the number of bit errors corrected. */
    {
      unsigned char
        w;                /* current syndrome limit weight, 2 or 3 */
      unsigned long
        mask;             /* mask for bit flipping */
      int
        i,j;              /* index */
      unsigned long
        s,                /* calculated syndrome */
        cwsaver;          /* saves initial value of cw */
    
      cwsaver=cw;         /* save */
      *errs=0;
      w=3;                /* initial syndrome weight threshold */
      j=-1;               /* -1 = no trial bit flipping on first pass */
      mask=1;
      while (j<23) /* flip each trial bit */
        {
          if (j != -1) /* toggle a trial bit */
            {
              if (j>0) /* restore last trial bit */
                {
                  cw=cwsaver ^ mask;
                  mask+=mask; /* point to next bit */
                }
              cw=cwsaver ^ mask; /* flip next trial bit */
              w=2; /* lower the threshold while bit diddling */
            }
    
          s=syndrome(cw); /* look for errors */
          if (s) /* errors exist */
            {
              for (i=0; i<23; i++) /* check syndrome of each cyclic shift */
                {
                  if ((*errs=weight(s)) <= w) /* syndrome matches error pattern */
                    {
                      cw=cw ^ s;              /* remove errors */
                      cw=rotate_right(cw,i);  /* unrotate data */
                      return(s=cw);
                    }
                  else
                    {
                      cw=rotate_left(cw,1);   /* rotate to next pattern */
                      s=syndrome(cw);         /* calc new syndrome */
                    }
                }
              j++; /* toggle next trial bit */
            }
          else
            return(cw); /* return corrected codeword */
        }
    
      return(cwsaver); /* return original if no corrections */
    } /* correct */
    
    /* ====================================================== */
    
    int decode(int correct_mode, int *errs, unsigned long *cw)
    /* This function decodes codeword *cw in one of two modes. If correct_mode
      is nonzero, error correction is attempted, with *errs set to the number of
      bits corrected, and returning 0 if no errors exist, or 1 if parity errors
      exist. If correct_mode is zero, error detection is performed on *cw,
      returning 0 if no errors exist, 1 if an overall parity error exists, and
      2 if a codeword error exists. */
    {
      unsigned long parity_bit;
    
      if (correct_mode)               /* correct errors */
        {
          parity_bit=*cw & 0x800000l; /* save parity bit */
          *cw&=~0x800000l;            /* remove parity bit for correction */
    
          *cw=correct(*cw, errs);     /* correct up to three bits */
          *cw|=parity_bit;            /* restore parity bit */
    
          /* check for 4 bit errors */
          if (parity(*cw))            /* odd parity is an error */
            return(1);
          return(0); /* no errors */
        }
      else /* detect errors only */
        {
          *errs=0;
          if (parity(*cw)) /* odd parity is an error */
            {
              *errs=1;
              return(1);
            }
          if (syndrome(*cw))
            {
              *errs=1;
              return(2);
            }
          else
            return(0); /* no errors */
        }
    } /* decode */
    
    /* ====================================================== */
    
    void golay_test(void)
    /* This function tests the Golay routines for detection and correction
      of various patterns of error_limit bit errors. The error_mask cycles
      over all possible values, and error_limit selects the maximum number
      of induced errors. */
    {
      unsigned long
        error_mask,         /* bitwise mask for inducing errors */
        trashed_codeword,   /* the codeword for trial correction */
        virgin_codeword;    /* the original codeword without errors */
      unsigned char
        pass=1,             /* assume test passes */
        error_limit=3;      /* select number of induced bit errors here */
      int
        error_count;        /* receives number of errors corrected */
    
      virgin_codeword=golay(0x555); /* make a test codeword */
      if (parity(virgin_codeword))
        virgin_codeword^=0x800000l;
      for (error_mask=0; error_mask<0x800000l; error_mask++)
        {
          /* filter the mask for the selected number of bit errors */
          if (weight(error_mask) <= error_limit) /* you can make this faster! */
            {
              trashed_codeword=virgin_codeword ^ error_mask; /* induce bit errors */
    
              decode(1,&error_count,&trashed_codeword); /* try to correct bit errors */
    
              if (trashed_codeword ^ virgin_codeword)
                {
                  printf("Unable to correct %d errors induced with error mask = 0x%lX\n",
                    weight(error_mask),error_mask);
                  pass=0;
                }
    
              if (kbhit()) /* look for user input */
                {
                  if (getch() == 27) return; /* escape exits */
    
                  /* other key prints status */
                  printf("Current test count = %ld of %ld\n",error_mask,0x800000l);
                }
            }
        }
      printf("Golay test %s!\n",pass?"PASSED":"FAILED");
    }
    
    /* ====================================================== */
    
    void main(int argument_count, char *argument[])
    {
      int i,j;
      unsigned long l,g;
      const char *errmsg = "Usage: G DATA Encode/Correct/Verify/Test\n\n"
                 "  where DATA is the data to be encoded, codeword to be corrected,\n"
                 "  or codeword to be checked for errors. DATA is hexadecimal.\n\n"
                 "Examples:\n\n"
                 "  G 555 E      encodes information value 555 and prints a codeword\n"
                 "  G ABC123 C   corrects codeword ABC123\n"
                 "  G ABC123 V   checks codeword ABC123 for errors\n"
                 "  G ABC123 T   tests routines, ABC123 is a dummy parameter\n\n";
    
      if (argument_count != 3)
        {
          printf(errmsg);
          exit(0);
        }
    
      if (sscanf(argument[1],"%lx",&l) != 1)
        {
          printf(errmsg);
          exit(0);
        }
    
      switch (toupper(*argument[2]))
        {
          case 'E': /* encode */
            l&=0xfff;
            l=golay(l);
            if (parity(l)) l^=0x800000l;
            printf("Codeword = %lX\n",l);
            break;
    
          case 'V': /* verify */
            if (decode(0,&i,&l))
              printf("Codeword %lX is not a Golay codeword.\n",l);
            else
              printf("Codeword %lX is a Golay codeword.\n",l);
            break;
    
          case 'C': /* correct */
            g=l; /* save initial codeword */
            j=decode(1,&i,&l);
            if ((j) && (i))
              printf("Codeword %lX had %d bits corrected,\n"
                     "resulting in codeword %lX with a parity error.\n",g,i,l);
            else
              if ((j == 0) && (i))
                printf("Codeword %lX had %d bits corrected, resulting in codeword %lX.\n",g,i,l);
              else
                if ((j) && (i == 0))
                  printf("Codeword %lX has a parity error. No bits were corrected.\n",g);
                else
                  if ((j == 0) && (i == 0))
                    printf("Codeword %lX does not require correction.\n",g);
            break;
    
          case 'T': /* test */
            printf("Press SPACE for status, ESC to exit test...\n");
            golay_test();
            break;
    
          default:
            printf(errmsg);
            exit(0);
        }
    }
    
    /* end of G.C */


import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
	}
}