Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <mm_malloc.h>
  2. //#include <stdio.h>
  3. //#include <string.h>
  4. #include <cstdio>
  5. #include <cstring>
  6. //#include <stdlib.h>
  7. #include <cstdlib>
  8. #include <iostream>
  9. using namespace std;
  10. int sr(char *b, char **c, int j) {
  11. int i=0, k = 0, h=0, i1;
  12. j=0;
  13. while (b[i] != 0) {
  14. while (b[i] == ' ') {
  15. i++;
  16. }
  17. if (b[i] == 0) {
  18. return j;
  19. }
  20. c = (char**)realloc(c, (j + 1)*sizeof(char*));
  21. i1=i;
  22. while (b[i1] != '.' && b[i1] != ',' && b[i1] != ' ' && b[i1] !=0){
  23. h++;
  24. i1++;
  25. }
  26. c[j] = (char*)calloc((size_t) h+1, sizeof(char));
  27. for (k=0; k<h; k++, i++){
  28. c[j][k] = b[i];
  29. }
  30. j++;
  31. char *p1;
  32. char p = '.';
  33. p1 = strchr(&b[i+1], p);
  34. i = *p1 + 1;
  35. h = 0;
  36. }
  37. return j;
  38. }
  39.  
  40. int main() {
  41. int i, j, N;
  42. size_t l = 0;
  43. char **a = 0;
  44. char *b = 0;
  45. char **c=0;
  46. scanf("%d", &N);
  47. N++;
  48. a = (char**)calloc(N, sizeof(char*));
  49. for (i = 0; i < N; i++) {
  50. a[i] = (char*)calloc(81, sizeof(char));
  51. }
  52. for (i = 0; i < N; i++) {
  53. cin.getline(a[i], 80);
  54. }
  55. for (i = 0; i < N; i++) {
  56. l = l + strlen(a[i]) + 1;
  57. b = (char*)realloc(b, (l)*sizeof(char));
  58. strcat(b, a[i]);
  59. strcat(b, " ");
  60. }
  61. i=0;
  62. while (b[i]==' ') {
  63. i++;
  64. }
  65. b[i-1]='.';
  66. sr(b, c, j);
  67. printf("%d",j);
  68. return 0;
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement