Se le da una secuencia de enteros como entrada, terminada por un -1. (Es decir, los enteros de entrada pueden ser positivos, negativos o 0. A -1 en la entrada señala el final de la entrada).
-1 no se considera como parte de la entrada.
Encuentra el segundo número más grande en la entrada. Usted no puede utilizar matrices.
Los casos de prueba pasan pero el puntaje es 0.0
Aquí está el código
int main() { int a=-32768,b=-32768,temp=-32768; while(1) { scanf("%d",&a); if(a==-1) break; else if(a>0) { temp=b; b=a; } else { if(a>b) { temp=b; b=a; } else { temp=b; } } } printf("%d",temp); return 0; }
Mal cheque de valor en tu camino. Por ejemplo, como este.
#include #define EOI -1 //End Of Input int main(void){ int input, first, second; first = second = EOI; while(1){ if(1 != scanf("%d", &input)){ fprintf(stderr, "invalid input!\n"); return -1; } if(input == EOI) break; if(first == EOI){ first = input; } else if(first <= input){ second = first;//slide first = input; } else if(second == EOI || second < input){ second = input; } } if(second == EOI){//first == EOI || second == EOI fprintf(stderr, "No valid value is entered more than one!\n"); return -2; } printf("%d\n", second); return 0; }