#include<iostream>
using namespace std;
int longest_plateau(int* A, int n)
{
int i, length = 1;
for (i = 1; i < n; i++)
{
if (A[i - length] == A[i])
length++;
}
return length;//这个必须放在for循环后面哦!!!注意!!
}
int main()
{
int n;
cin >> n;
int a[128][1] = { 0 };
for (int i = 0; i < n; i++) {
cin >> a[i][0];
}
int buf;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i; j++) {
if (a[j][0] < a[j + 1][0]) {
buf = a[j][0];
a[j][0] = a[j + 1][0];
a[j + 1][0] = buf;
}
}
}
for (int i = 0; i < n; i++)
cout << a[i][0] << endl;
int b = 0;
b=longest_plateau(*a, n);
cout << b << endl;
for (int i = 0; i < n; i++)
if (a[i + b][0] == a[i][0])
cout << a[i][0] << endl;
}
求问各位大神,我用这段程序来求一个序列中的众数,要输入的是n(一共几个数),以及分别输入n个数,(这n个数因为要求分行输入,所以我用的是n行1列的数组),那请问为什么最后,输入较小的数时,这段程序可以成功运算出来,但是输入较大的数,比如+0001111111111,程序就运行不出来了呢?请
大神帮忙解答,谢谢!!!!
我的输入:
6
-00001
10000
00011111111111111111111111111111111111
-01
+000000011111111111111111111111111111111111
-00000000000001
我的输出:
6
-00001
10000
00011111111111111111111111111111111111
9223372036854775807
10000
0
0
0
0
4
0
0
0
int值范围:-2147483648 ~ 2147483647
用long替代int试下,其范围是:-9223372036854775808~9223372036854775807
https://blog.csdn.net/guoqingshuang/article/details/50191063