1 条题解
-
0
C :
#include<stdio.h> void main() { int max1,max,x,m; while(scanf("%d",&x)!=EOF) { max=max1=0; for(x;x>0;x--) { scanf("%d",&m); if(m>max){max1=max;max=m;} if(max>m&&max1<m)max1=m; } printf("%d\n",max1); } }
C++ :
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> using namespace std; int main() { int n, a[200]; while(scanf("%d",&n) != EOF) { for(int i = 0 ; i < n ; i ++) scanf("%d",&a[i]); int max = -1, max2 = -1; for(int i = 0 ; i < n ; i ++) { if(a[i] > max) { max2 = max; max = a[i]; } else if (a[i] > max2 && a[i] != max) { max2 = a[i]; } } cout << max2 << endl; } //while(scanf("%d",&n) != EOF) //{ // int a, b, x, sum = 0; // for(int i = 0 ; i < n ; i ++) // { // cin >> x; // if(i == 0) // a = x; // if(x != a) // b = x; // if(x == a) // sum ++; // else // sum --; // } // if(sum > 0) // cout << a << endl; // else // cout << b << endl; //} }
- 1
信息
- ID
- 3313
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者