RiQ363

Lab 6v3

Dec 26th, 2011
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // 3
  2. #include <iostream.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #define DELIMITERS " .,:;\n\t"
  9.  
  10. void funkcia1(char *s)
  11. {
  12. int i=0,f,k,j=0,l=strlen(s);
  13. char c[255],b;
  14.  
  15.  
  16. while(i<l)
  17. {
  18. while(s[i]==' ')
  19. i++;
  20.  
  21. f=0;
  22. k=i;
  23. while((s[i]!=' ')&&(s[i]!='\0'))
  24. {
  25. if(s[i]==s[i+1])
  26. f=1;//f=1
  27. i++;
  28. }
  29. if(f==1)
  30. {
  31. if((s[k]>='A')&&(s[k]<='Z'))
  32. {
  33. c[j]=s[k];
  34. j++;
  35. }
  36. }
  37. i++;
  38. }
  39.  
  40. f=1;
  41. while(f!=0)
  42. {
  43. f=0;
  44. for(i=0;i<j-1;i++)
  45. {
  46. if(c[i]>c[i+1])
  47. {
  48. b=c[i];
  49. c[i]=c[i+1];
  50. c[i+1]=b;
  51. f=1;
  52. }
  53. }
  54. }
  55. printf("\n");
  56. for(i=0;i<j;i++)
  57. printf("%c\t",c[i]);
  58. printf("\n");
  59. }
  60.  
  61. void funkcia2(char *s)
  62. {
  63. int i=0,f,ff,k,l=strlen(s),len=0,m=-1;
  64. char c[100],b;
  65.  
  66.  
  67. while(i<l)
  68. {
  69. while((s[i]==' ')||(s[i]=='\0'))
  70. i++;
  71. f=0;
  72. ff=0;
  73. k=i;
  74. i++;
  75. while((s[i]!=' ')&&(s[i]!='\0'))
  76. {
  77. if((s[i]>='A')&&(s[i]<='Z'))
  78. {
  79. if(s[i]!=s[i-1])
  80. f=1;
  81. }
  82. else ff=1;
  83. i++;
  84. }
  85. if((f==0)&&(ff==0))
  86. {
  87. if((i-k)>len)
  88. {
  89. len=i-k;
  90. m=k;
  91. }
  92. }
  93. i++;
  94. }
  95.  
  96. if(m==-1)printf("net regulyarnih cepochek");
  97. else
  98. for(i=m;i<len+m;i++)
  99. printf("%c",s[i]);
  100. printf("\n");
  101. }
  102.  
  103.  
  104. int main()
  105. {
  106. char s[500];
  107. char *word;
  108. printf("Str= ");
  109. /*fgets(s,500,stdin);
  110. word=strtok(s,DELIMITERS);
  111. while(word!=NULL)
  112. {
  113. puts(word);
  114. word=strtok(NULL,DELIMITERS);
  115. } */
  116.  
  117. gets(s);
  118. printf("\nPostroyenie po alphavitu");
  119. funkcia1(s);
  120.  
  121. printf("Samaya dlinnaya cepochka:\n");
  122. funkcia2(s);
  123.  
  124. getch();
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment