Source code for submission s829

fs.c

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. int main(void)
  6. {
  7. char abc[30][5] = { ".-" , "-..." , "-.-." , "-.." , "." , "..-." , "--." , "...." , ".." , ".---" , "-.-" , ".-.." , "--" , "-." , "---" , ".--." , "--.-" , ".-." , "..." , "-" , "..-" , "...-" , ".--" , "-..-" , "-.--" , "--..", "..--", "---.", ".-.-", "----"};
  8. char c;
  9. int cisla[1000];
  10. char *str;
  11. char *vyb;
  12. int pocet=0, poc2=0, i=0;
  13. str = (char*) malloc(4001);
  14. vyb = (char*) malloc(5);
  15. while(scanf("%c",&c)>0)
  16. {
  17. if(c=='\n')
  18. {
  19. pocet--;
  20. while(pocet>=0)
  21. {
  22. strncpy(vyb,&str[poc2],cisla[pocet]);
  23. poc2+=cisla[pocet];
  24. pocet--;
  25. for(i=0; i<30; i++)
  26. {
  27. if(strcmp(vyb,abc[i])==0)
  28. {
  29. if(i<26)
  30. printf("%c",'A' + i);
  31. else
  32. {
  33. if(i==26)
  34. printf("_");
  35. else if(i==27)
  36. printf(".");
  37. else if(i==28)
  38. printf(",");
  39. else
  40. printf("?");
  41. }
  42. }
  43.  
  44. }
  45. free(vyb);
  46. vyb = (char*) malloc(5);
  47. }
  48. free(str);
  49. str = (char*) malloc(4001);
  50. str[0] = '\0';
  51. printf("\n");
  52. pocet=0;
  53. poc2=0;
  54. }
  55. else
  56. {
  57. if((c>='A') && (c<='Z'))
  58. {
  59. strcat(str,abc[c-'A']);
  60. cisla[pocet]=strlen(abc[c-'A']);
  61. }
  62. else
  63. {
  64. if(c=='_')
  65. strcat(str,"..--");
  66. else if(c==',')
  67. strcat(str,".-.-");
  68. else if(c=='.')
  69. strcat(str,"---.");
  70. else
  71. strcat(str,"----");
  72. cisla[pocet]=4;
  73. }
  74. pocet++;
  75. }
  76. }
  77. return 0;
  78. }
  79.  
  80.