Mira2706

recursions

Jan 10th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*
  6. bool isAlpha(char c)
  7. {
  8. return ((c>='A' && c<='Z') || (c>='a' && c<='z'));
  9. }
  10.  
  11.  
  12. bool isAllAlpha(char arr[])
  13. {
  14.  
  15. bool flag = true;
  16. int size = len(arr);
  17. for(i = 0; i<len(arr); i++)
  18. {
  19. if(!isAllAlpha(arr[i]))
  20. {
  21. return false;
  22. }
  23. }
  24. }
  25. */
  26.  
  27. /*
  28. bool isNumber(char *niz)
  29. {
  30. for (int i = 0; i<len(niz); i++)
  31. {
  32. if('0' > niz[i] || niz[i] > '9')
  33. {
  34. return false;
  35. }
  36. }
  37. return true;
  38. }
  39.  
  40. int toNumber (char *niz)
  41. {
  42. if (isNumber(niz))
  43. {
  44.  
  45. int number = 0;
  46. for(int i = 0; i<len(niz); i++)
  47. {
  48. number *= 10;
  49. number += (int)niz[i] - '0';
  50.  
  51. }
  52. return number;
  53. }
  54. return -1;
  55. }
  56. */
  57.  
  58. int countMatches(int x, int k)
  59. {
  60. if(x%10 == k)
  61. {
  62. return 1 + countMatches(x/10, k)
  63. }
  64. if (abs(x)<=9)
  65. {
  66. if(x == 0)
  67. {
  68. return 0;
  69. }
  70. return countMatches(x/10, k);
  71. }
  72.  
  73.  
  74. }
  75.  
  76. void printHelper(int k, int n)
  77. {
  78.  
  79. if(k == n)
  80. {
  81. cout<<n<<endl;
  82. }
  83. else
  84. {
  85. printHelper(k+1, n);
  86. for(int i = 1; i>= k; i--)
  87. {
  88. cout<<i<<" ";
  89.  
  90. }
  91. cout<<endl;
  92.  
  93. }
  94. }
  95.  
  96. int comp(char a[], char b[], int index)
  97. {
  98. if (a[index] == '\0')
  99. {
  100. if(b[index] == '\0'){
  101. return 0;
  102. }
  103. return -1;
  104. }
  105. if (b[index] == '\0')
  106. {
  107. return 1;
  108. }
  109. if (a[index] < b[index])
  110. {
  111. return -1;
  112. }
  113. if(a[index == b[index]){
  114. return comp(a, b, ++index);
  115. }
  116. if(a[index] > b[index]){
  117. return -1;
  118. }
  119. }
  120.  
  121.  
  122. int main()
  123. {
  124.  
  125.  
  126.  
  127.  
  128.  
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment