Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Created June 26, 2011 10:25
Show Gist options
  • Save rkotov93/1047482 to your computer and use it in GitHub Desktop.
Save rkotov93/1047482 to your computer and use it in GitHub Desktop.
task
#include <stdio.h>
#include <limits.h>
int upOrder(int n) {
int k;
int f = n % 10;
n /= 10;
while (n > 0) {
k = n % 10;
if (k < f) return 0;
f = k;
n /= 10;
}
return 1;
}
int downOrder(int n) {
int k;
int f = n % 10;
n /= 10;
while (n > 0) {
k = n % 10;
if (k > f) return 0;
f = k;
n /= 10;
}
return 1;
}
int main() {
int num;
int i;
int max = INT_MIN;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
while (scanf("%d", &num) > 0)
if (upOrder(num) || downOrder(num)) if (num > max) max = num;
if (max == INT_MIN) printf("0");
else printf("%d", max);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment