Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. char * NotEmptyArr(char* arr) {
  6. string str = arr;
  7. while (str.length() == 0) {
  8. cout << "The input cannot be empty"<<endl;
  9. cin.getline(arr, 100);
  10. str = arr;
  11. }
  12. return arr;
  13. }
  14.  
  15. void PrintResultString(string str1, string str2) {
  16. int maxSize = 0;
  17. int minSize = 0;
  18. if (str1.length() > str2.length()) {
  19. maxSize = str1.length();
  20. minSize = str2.length();
  21. }
  22. else {
  23. maxSize = str2.length();
  24. minSize = str1.length();
  25. }
  26.  
  27. int counter = 0;
  28.  
  29. string result[100];
  30. for (int i = 0; i < maxSize; i++)
  31. {
  32. if (maxSize == str1.length()) {
  33. result[i] = str2[counter];
  34. if (counter == str2.length() - 1) {
  35. counter = -1;
  36. }
  37. counter++;
  38. }
  39. else {
  40. result[i] = str1[counter];
  41. if (counter == str1.length() - 1) {
  42. counter = -1;
  43. }
  44. counter++;
  45. }
  46. }
  47. for (int i = 0; i < maxSize; i++)
  48. {
  49. cout << result[i];
  50. }
  51.  
  52.  
  53. }
  54.  
  55. int main()
  56. {
  57. char arr1[100];
  58. char arr2[100];
  59. cout << "arr1= ";
  60. cin.getline(arr1, 100);
  61.  
  62. //check if arr1 is empty
  63. string str1 = NotEmptyArr(arr1);
  64.  
  65. cout << "arr2= ";
  66. cin.getline(arr2, 100);
  67. //check if arr2 is empty
  68. string str2 = NotEmptyArr(arr2);
  69.  
  70. //check whether the two strings are of different size
  71. if (str1.length() == str2.length()) {
  72. cout << "The inputs should be of different size. "<<endl;
  73. return main();
  74. }
  75.  
  76.  
  77. PrintResultString(str1, str2);
  78.  
  79.  
  80. //!!!!!! trqbva funkciqta da e string, a ne void i da vrushta result
  81.  
  82. //kak da proverq dali nqkoj masiv e prazen
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. //zashto ne raboti
  92. //cout << result;
  93.  
  94. // kak da izpechatam rezultata bez cikul
  95.  
  96.  
  97.  
  98. //zashto ne moga na masiv da prisvoq stoinostta na string
  99. // \t ...ne raboti kato primera ako stoinostta na stringa e vkarana ot konzolata- tova normalno li e?
  100. // pri proverkata dali e empty ne mi izliza tekst: arr1/2= ....
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement