Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <limits.h>
- int parse(char* ptr, int* i) {
- int value = 0;
- for (; ptr[*i] <= '9' && ptr[*i] >= '0'; ++(*i))
- value = value * 10 + ptr[*i] - '0';
- return value;
- }
- int find_max(char* a) {
- int i = 0;
- int max = INT_MIN,
- curr = INT_MIN;
- while (a[i]) {
- if (a[i] == '-' && a[i + 1] <= '9' && a[i + 1] >= '0') {
- i++;
- curr = -parse(a, &i);
- if (curr > max)
- max = curr;
- i++;
- }
- else if (a[i + 1] <= '9' && a[i + 1] >= '0') {
- curr = parse(a, &i);
- if (curr > max)
- max = curr;
- }
- else
- i++;
- }
- return max;
- }
- int main() {
- char a[] = "- --privet -13 -257 -300";
- printf("%d\n", find_max(a));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement