Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include "cmath"
- using namespace std;
- int main()
- {
- int i, j;
- char s[100];
- char s1[100];
- char s2[100];
- char res[100];
- cout << "Vvedite stroky: " << endl;
- cin >> s;
- int len = strlen(s);
- for (i = 1; i < len - 1; i++)
- {
- strcpy_s(res, "");
- if (s[i] == '.')
- {
- strcpy_s(s1, "");
- for (j = i - 1; j >= 0; j--)
- {
- 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')
- {
- char tmp[100];
- strcpy_s(tmp, s1);
- strcpy_s(s1, "");
- s1[0] = s[j];
- strcat_s(s1, tmp);
- }
- else
- {
- break;
- }
- }
- strcpy_s(s2, "\0");
- for (j = i + 1; j < len; j++)
- {
- 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')
- {
- s2[j - i - 1] = s[j];
- s2[j - i] = '\0';
- }
- else
- {
- break;
- }
- }
- if (strlen(s1) > 0 && strlen(s2) > 0)
- {
- bool plus = false;
- int t = i - strlen(s1) - 1;
- if (t >= 0)
- {
- if (s[t] == '+' || s[t] == '-')
- {
- res[0] = s[t];
- res[1] = '\0';
- plus = true;
- }
- }
- strcat_s(res, s1);
- if (plus)
- {
- res[strlen(s1) + 1] = s[i];
- res[strlen(s1) + 2] = '\0';
- }
- else
- {
- res[strlen(s1)] = s[i];
- res[strlen(s1) + 1] = '\0';
- }
- strcat_s(res, s2);
- break;
- }
- }
- }
- if (strlen(res) > 0)
- {
- cout << res << endl;
- }
- else
- {
- cout << "Ne naideno!" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment