Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3.  
  4.  
  5. int parse(char* ptr, int* i) {
  6. int value = 0;
  7. for (; ptr[*i] <= '9' && ptr[*i] >= '0'; ++(*i))
  8. value = value * 10 + ptr[*i] - '0';
  9. return value;
  10. }
  11.  
  12. int find_max(char* a) {
  13. int i = 0;
  14. int max = INT_MIN,
  15. curr = INT_MIN;
  16. while (a[i]) {
  17. if (a[i] == '-' && a[i + 1] <= '9' && a[i + 1] >= '0') {
  18. i++;
  19. curr = -parse(a, &i);
  20. if (curr > max)
  21. max = curr;
  22. i++;
  23. }
  24. else if (a[i + 1] <= '9' && a[i + 1] >= '0') {
  25. curr = parse(a, &i);
  26. if (curr > max)
  27. max = curr;
  28.  
  29. }
  30. else
  31. i++;
  32.  
  33. }
  34. return max;
  35. }
  36.  
  37. int main() {
  38. char a[] = "- --privet -13 -257 -300";
  39. printf("%d\n", find_max(a));
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement