Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. void swapInput(char input[],char swapedInput[]) {
  5. int counter = 0;
  6. while (input[counter] != '\0') {
  7. counter++;
  8. }
  9. counter--;
  10. int i;
  11. for (i = 0;input[i] != '\0';i++,counter--) {
  12. swapedInput[i] = input[counter];
  13. }
  14. swapedInput[i] = '\0';
  15. }
  16. bool doExist_(char* symbols, char* word) {
  17. char swapedInput[100];
  18. bool sameWord = true;
  19. swapInput(symbols, swapedInput);
  20. for (int i = 0;swapedInput[i] != '\0';i++) {
  21. if (swapedInput[i] == word[0]) {
  22. for (int j = i, k = 0;word[k] != '\0';j++, k++) {
  23. if (swapedInput[j] != word[k]) {
  24. sameWord = false;
  25. break;
  26. }
  27. }
  28. }
  29. }
  30. if (sameWord == true) {
  31. return true;
  32. }
  33. return false;
  34.  
  35. }
  36. int* CheckNums(long num1, long num2) {
  37. int numbers[10000];
  38. int i_numbers = 0;
  39. int digit1;
  40. int digit2;
  41. long copyOfnum2;
  42. while (num1 != 0) {
  43. digit1 = num1 % 10;
  44. copyOfnum2 = num2;
  45. while (copyOfnum2 != 0) {
  46. digit2 = copyOfnum2 % 10;
  47. if (digit1 == digit2) {
  48. numbers[i_numbers] = digit1;
  49. i_numbers++;
  50. }
  51. copyOfnum2 /= 10;
  52. }
  53. num1 /= 10;
  54. }
  55. return numbers;
  56. }
  57. int strLen(char input[]) {
  58. int counter = 0;
  59. for (counter;input[counter] != '\0';counter++);
  60. return counter;
  61. }
  62. long getWords(char str[])
  63. {
  64. long count = 0;
  65. long strLength = strLen(str);
  66.  
  67. int currentPosition = 0;
  68.  
  69. char words[100][100]{ 0 };
  70.  
  71. if (strLength == 0)
  72. return -1;
  73.  
  74. for (int i = 0; i <= strLen(str); i++)
  75. {
  76. if (str[i] != ' ' && str[i] != '\t' && str[i] != '\0')
  77. {
  78. words[count][currentPosition] = str[i];
  79. currentPosition++;
  80. }
  81. else if ((str[i] == ' ' || str[i] == '\t' || str[i] == '\0') && str[i - 1] != '\t' && str[i - 1] != ' ')
  82. {
  83. count++;
  84. currentPosition = 0;
  85. }
  86. }
  87.  
  88. for (int i = 0; i < count; i++)
  89. {
  90. std::cout << words[i] << "-";
  91. }
  92.  
  93.  
  94. return count;
  95.  
  96. }
  97. int lenghtOfNumber(long number) {
  98. int digit = 0;
  99. while (number != 0) {
  100. number /= 10;
  101. digit++;
  102.  
  103. }
  104. return digit;
  105. }
  106. int convertNumber(long num) {
  107. int sum = 0;
  108. while (num != 0) {
  109. sum += num % 10;
  110. num /= 10;
  111. }
  112. return sum;
  113. }
  114. void reverse(char input[]) {
  115. int difference = abs('a' - 'A');
  116. //cout << difference << endl;
  117. for (int i = 0;input[i] != '\0';i++) {
  118. if ((input[i] >= 'a' && input[i] <= 'z') || (input[i] >= 'A' && input[i] <= 'Z')) {
  119. if (input[i] >= 'A'&& input[i] <= 'Z') {
  120. input[i] += difference;
  121. cout << input[i];
  122. }
  123. else {
  124. input[i] -= difference;
  125. cout << input[i];
  126. }
  127. }
  128. }
  129. //return input;
  130. }
  131. bool doExist(char* symbols, char* word) {
  132. bool notSameWord = false;
  133. for (int i = 0;symbols[i] != '\0';i++) {
  134. if (symbols[i] == word[0]) {
  135. for (int j = 0,k=i;word[j] != '\0'&& symbols[i] != '\0';j++, k++) {
  136. notSameWord = false;
  137. if (word[j] != symbols[k]) {
  138. notSameWord = true;
  139. break;
  140. }
  141. }
  142. }
  143. }
  144. if (notSameWord == true) {
  145. return false;
  146. }
  147. else {
  148. return true;
  149. }
  150. }
  151. int DigitPos(long num, int k) {
  152. int digit = -1;
  153. if (k > lenghtOfNumber(num)) {
  154. return -1;
  155. }
  156. else {
  157. digit = num / pow(10, (lenghtOfNumber(num) - k));
  158. digit = digit % 10;
  159. return digit;
  160. }
  161. }
  162. /*bool CheckDate(char input[]) {
  163. int days=0;
  164. int months = 0;
  165. int i = 0;
  166. if (strLen(input) > 5) {
  167. return false;
  168. }
  169. for (i = 0;input[i] != '.';i++) {
  170. days += input[i] - '0';
  171. }
  172. for (i = i + 1;input[i] != '\0';i++) {
  173. months += input[i] - '0';
  174. }
  175. if (months == 1) {
  176. if (days > 31) {
  177. return false;
  178. }
  179. }
  180. if (months == 2) {
  181. if (days > 29) {
  182. return false;
  183. }
  184. }
  185. if (months == 3) {
  186. if (days > 31) {
  187. return false;
  188. }
  189. }
  190. if (months == 4) {
  191. if (days > 30) {
  192. return false;
  193. }
  194. }
  195.  
  196. }*/
  197. void arrayOfIntNumbers(int num1[], int num2[],int size1,int size2) {
  198. int sameNumbers[100];
  199. int sortedArr[100];
  200. int i_sameNumbers = 0;
  201. for (int i = 0;i < size1;i++) {
  202. for (int j = 0;j < size2;j++) {
  203. if (num1[i] == num2[j]) {
  204. sameNumbers[i_sameNumbers] = num1[i];
  205. i_sameNumbers++;
  206. }
  207. }
  208. }
  209. int temp;
  210. for (int i = 0;i < i_sameNumbers-1;i++) {
  211. for (int j = i+1;j < i_sameNumbers;j++) {
  212. if (sameNumbers[i] > sameNumbers[j]) {
  213. temp = sameNumbers[i];
  214. sameNumbers[i] = sameNumbers[j];
  215. sameNumbers[j] = temp;
  216. }
  217. }
  218. }
  219. for (int i = 0;i < i_sameNumbers;i++) {
  220. cout << sameNumbers[i] << " ";
  221. }
  222. }
  223. void rectangle(int n, int m, char p) {
  224. char rectangleArr [100][100];
  225. for (int i = 0;i < n;i++) {
  226. for (int j = 0;j < m;j++) {
  227. rectangleArr[i][j] = p;
  228. cout << rectangleArr[i][j];
  229. }
  230. cout << endl;
  231. }
  232. }
  233. int sumOfDiagonal(int n, int arr[][100]) {
  234. int sum=0;
  235. for (int i = 0;i < n;i++) {
  236. for (int j = 0;j < n;j++) {
  237. if (j > i) {
  238. sum += arr[i][j];
  239. }
  240. }
  241. }
  242. return sum;
  243. }
  244. void transponate(int matrix[][100],int n) {
  245. int transponatedMatrix[100][100] { 0 };
  246. cout << endl;
  247. for (int i = 0;i < n;i++) {
  248. for (int j = 0;j < n;j++) {
  249. transponatedMatrix[i][j] = matrix[j][i];
  250. cout << transponatedMatrix[i][j] << " ";
  251. }
  252. cout << endl;
  253. }
  254. }
  255. void multuplyingMatrix(int** matrix1, int** matrix2, int size) {
  256. int** multiply = new int* [size];
  257. for (int i = 0;i < size;i++) {
  258. multiply[i] = new int[size];
  259. }
  260. for (int i = 0;i < size;i++) {
  261. for (int j = 0;j < size;j++) {
  262. multiply[i][j] = 0;
  263. for (int k = 0;k < size;k++) {
  264. multiply[i][j] += matrix1[i][k] * matrix2[k][j];
  265. }
  266.  
  267. }
  268. }
  269. cout << endl;
  270. for (int i = 0;i < size;i++) {
  271. for (int j = 0;j < size;j++) {
  272. cout << multiply[i][j] << " ";
  273. }
  274. cout << endl;
  275. }
  276. }
  277. void bubbleSort(int arrayInt[],int size) {
  278. int swap = 0;
  279. for (int i = 0;i < size;i++) {
  280. swap = 0;
  281. for (int j = i + 1;j < size;j++) {
  282. if (arrayInt[i] > arrayInt[j]) {
  283. swap = arrayInt[i];
  284. arrayInt[i] = arrayInt[j];
  285. arrayInt[j] = swap;
  286. }
  287. }
  288. }
  289. for (int i = 0;i < size;i++) {
  290. cout << arrayInt[i] << " ";
  291. }
  292. }
  293. void swapElements(int array[], int size, int start, int end) {
  294. int swap;
  295. for (int i = start,j=end;i <= (start + end) / 2;i++,j--) {
  296. swap = array[i];
  297. array[i] = array[j];
  298. array[j] = swap;
  299. swap = 0;
  300. }
  301. cout << endl;
  302. for (int i = 0;i < size;i++) {
  303. cout << array[i] << " ";
  304. }
  305.  
  306. }
  307. void transformateNumbers(char input[]) {
  308. for (int i = 0;input[i] != '\0';i++) {
  309. if (input[i] >= '0' && input[i] <= '9') {
  310. input[i] = '9' - input[i] +'0';
  311. }
  312. }
  313. for (int i = 0;input[i] != '\0';i++) {
  314. cout << input[i];
  315. }
  316. }
  317. void multiplyMatrixAgain(int** matrix1, int** matrix2, int size) {
  318. int** answer = new int* [size];
  319. for (int i = 0;i < size;i++) {
  320. answer[i] = new int[size];
  321. }
  322. for (int i = 0;i < size;i++) {
  323. for (int j = 0;j < size;j++) {
  324. answer[i][j] = 0;
  325. for (int k = 0;k < size;k++) {
  326. answer[i][j] += matrix1[i][k] * matrix2[k][j];
  327. }
  328.  
  329. }
  330. }
  331. for (int i = 0;i < size;i++) {
  332. for (int j = 0;j < size;j++) {
  333. cout << answer[i][j] << " ";
  334. }
  335. cout << endl;
  336. }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement