String Task


SUBMITTED BY: Guest

DATE: March 12, 2014, 1:53 p.m.

FORMAT: Text only

SIZE: 2.6 kB

HITS: 771

  1. //Haha TTPro
  2. //http://codeforces.com/problemset/problem/118/A
  3. //String Task
  4. #include <iostream>
  5. #include <string.h>
  6. using namespace std;
  7. struct NODE
  8. {
  9. char cha;
  10. NODE * pNext;
  11. };
  12. void input(NODE*&head, char X[]);
  13. void output(NODE*&head);
  14. void Clean(NODE*&head);
  15. void DeVowels(NODE*&head);
  16. bool CheckVowels(char x);
  17. void DeDummyNodehead(NODE*&head);
  18. void DummyNodehead(NODE*&head);
  19. void Replace(NODE*& head);
  20. void Up(char &x);
  21. int main()
  22. {
  23. char X[120];
  24. cin.getline(X, 120);
  25. NODE*head = NULL;
  26. DummyNodehead(head);
  27. input(head,X);
  28. DeVowels(head);
  29. DeDummyNodehead(head);
  30. Replace(head);
  31. output(head);
  32. Clean(head);
  33. }
  34. void DummyNodehead(NODE*&head)
  35. {
  36. head = new NODE;
  37. head->pNext = NULL;
  38. }
  39. void DeDummyNodehead(NODE*&head)
  40. {
  41. NODE*K;
  42. K = head;
  43. head = head->pNext;
  44. delete K;
  45. }
  46. void CreateNode(NODE*&K, char a)
  47. {
  48. K = new NODE;
  49. K->cha = a;
  50. K->pNext = NULL;
  51. }
  52. void input(NODE*&head, char X[])
  53. {
  54. char a;
  55. NODE *K,*cur;
  56. cur = head;
  57. for (int i =0; i < strlen(X);i++)
  58. {
  59. a=X[i];
  60. if (a == '\0') break;
  61. CreateNode(K,a);
  62. cur->pNext = K;
  63. cur = cur->pNext;
  64. }
  65. }
  66. void output(NODE*&head)
  67. {
  68. NODE*cur;
  69. cur = head;
  70. while (cur != NULL)
  71. {
  72. cout << ".";
  73. cout << cur->cha;
  74. cur = cur->pNext;
  75. }
  76. }
  77. void Clean(NODE*&head)
  78. {
  79. NODE*cur;
  80. cur = head;
  81. while (cur!=NULL)
  82. {
  83. head = head->pNext;
  84. delete cur;
  85. cur = head;
  86. }
  87. }
  88. void DeVowels(NODE*&head)
  89. {
  90. NODE*cur;
  91. NODE*del;
  92. cur = head;
  93. while (cur->pNext != NULL)
  94. {
  95. while (CheckVowels(cur->pNext->cha))
  96. {
  97. del = cur->pNext;
  98. cur->pNext = del->pNext;
  99. delete del;
  100. if (cur->pNext == NULL) break;
  101. }
  102. cur = cur->pNext;
  103. if (cur == NULL) break;
  104. }
  105. }
  106. bool CheckVowels(char x)
  107. {
  108. if ((x == 'A') || (x == 'a') || (x == 'O') || (x == 'o') || (x == 'E') || (x == 'e') || (x == 'Y') || (x == 'y') || (x == 'U') || (x == 'u') || (x == 'i') || (x == 'I'))
  109. {
  110. return true;
  111. }
  112. return false;
  113. }
  114. void Up(char &x)
  115. {
  116. if ((x >= 65) && (x <= 90))
  117. {
  118. x = x + 32;
  119. }
  120. }
  121. void Replace(NODE*& head)
  122. {
  123. if (head == NULL) return;
  124. NODE* cur = head;
  125. while (cur != NULL)
  126. {
  127. Up(cur->cha);
  128. cur = cur->pNext;
  129. }
  130. }

comments powered by Disqus