MaksNew

Untitled

Dec 14th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include "cmath"
  4. using namespace std;
  5. int main()
  6. {
  7. int i, j;
  8. char s[100];
  9. char s1[100];
  10. char s2[100];
  11. char res[100];
  12. cout << "Vvedite stroky: " << endl;
  13. cin >> s;
  14. int len = strlen(s);
  15. for (i = 1; i < len - 1; i++)
  16. {
  17. strcpy_s(res, "");
  18. if (s[i] == '.')
  19. {
  20. strcpy_s(s1, "");
  21. for (j = i - 1; j >= 0; j--)
  22. {
  23. if (s[j] == '0' || s[j] == '1' || s[j] == '2' || s[j] == '3' || s[j] == '4' || s[j] == '5' || s[j] == '6' || s[j] == '7' || s[j] == '8' || s[j] == '9')
  24. {
  25. char tmp[100];
  26. strcpy_s(tmp, s1);
  27. strcpy_s(s1, "");
  28. s1[0] = s[j];
  29. strcat_s(s1, tmp);
  30. }
  31. else
  32. {
  33. break;
  34. }
  35. }
  36. strcpy_s(s2, "\0");
  37. for (j = i + 1; j < len; j++)
  38. {
  39. if (s[j] == '0' || s[j] == '1' || s[j] == '2' || s[j] == '3' || s[j] == '4' || s[j] == '5' || s[j] == '6' || s[j] == '7' || s[j] == '8' || s[j] == '9')
  40. {
  41. s2[j - i - 1] = s[j];
  42. s2[j - i] = '\0';
  43. }
  44. else
  45. {
  46. break;
  47. }
  48. }
  49. if (strlen(s1) > 0 && strlen(s2) > 0)
  50. {
  51. bool plus = false;
  52. int t = i - strlen(s1) - 1;
  53. if (t >= 0)
  54. {
  55. if (s[t] == '+' || s[t] == '-')
  56. {
  57. res[0] = s[t];
  58. res[1] = '\0';
  59. plus = true;
  60. }
  61. }
  62. strcat_s(res, s1);
  63. if (plus)
  64. {
  65. res[strlen(s1) + 1] = s[i];
  66. res[strlen(s1) + 2] = '\0';
  67. }
  68. else
  69. {
  70. res[strlen(s1)] = s[i];
  71. res[strlen(s1) + 1] = '\0';
  72. }
  73. strcat_s(res, s2);
  74. break;
  75. }
  76. }
  77. }
  78. if (strlen(res) > 0)
  79. {
  80. cout << res << endl;
  81. }
  82. else
  83. {
  84. cout << "Ne naideno!" << endl;
  85. }
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment