Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- bool isValidNumber(std::string a) {
- size_t sz = a.size();
- if (sz == 0) {
- return false;
- }
- int cnt = 0;
- int last = 0;
- for (size_t i = 0; i < sz; ++i) {
- if ((a[i] == '.') || (a[i] == ',')) {
- cnt++;
- last = i;
- }
- }
- if (cnt == 0) {
- return (a[0] != '0');
- } else {
- if (cnt > 1) {
- return false;
- } else {
- if ((last == 0) || (last == sz - 1)) {
- return false;
- } else {
- return ((a[0] != '0') && (a[sz - 1] != '0'));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement