Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string s;
- int i = 0, k = -1;
- cout << "Введите выражение\n";
- cin >> s;
- while (i < s.length())
- {
- if (s[0] == '+' || s[0] == '-' )
- {
- k = 0;
- break;
- }
- if (s[s.length() - 1] == '+' || s[s.length() - 1] == '-')
- {
- k = s.length() - 1;
- break;
- }
- if ((s[i] >= '0' && s[i] <= '9') || s[i] == '+' || s[i] == '-')
- {
- if ((s[i] == '-' || s[i] == '+') && (s[i - 1] == '+' || s[i - 1] == '-'))
- {
- k = i;
- break;
- }
- i++;
- }
- else
- {
- k = i;
- break;
- }
- }
- if (k == -1)
- cout << "0" << endl;
- else
- cout << "Номер ошибочного элемента "<< k+1 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement