TA的每日心情 | 开心 2014-6-18 08:29 |
---|
签到天数: 14 天 [LV.3]偶尔看看II
滴水大师
 
- 积分
- 2345
|
题目
解决代码及点评[cpp] view plaincopy![]() ![]()
- <pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"></pre><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code"><pre code_snippet_id="91880" snippet_file_name="blog_20131202_1_2646179" class="cpp" name="code">/*
- 功能:编写求最大平台问题的程序。
- 有n个整数a1,a2, ... an, 若满足a1≤a2≤ ... ≤ an ,
- 则认为在这n个数中有最大平台。在这种情况下,若n个数互不相同,
- 则最大平台值为1,若在n个数中最多有连续m个整数的值相等,则最大平台值为m。
- 例如: n=10时
- 1,2,3,4,5,6,6,7,4,5 无最大平台
- 1,1,2,2,2,2,2,2,2,2 最大平台值为8
- 1,1,2,2,2,3,3,4,4,5 最大平台值为3
- 0,1,2,3,4,5,6,7,8,9 最大平台值为1
-
- 时间:2:14 2013/10/26
- */
-
- #include<stdio.h>
- #include <stdlib.h>
-
- int judgHas59(int *a,int n); //判断是否有平台
- int judg1(int *a,int n); //最大平台是否为1
- int getBiggst(int *a,int n); //获取最大平台
-
- void main()
- {
- const int N=10;
- int a[N];
- for(int i=0;i<N;i++)scanf_s("%d",&a); //给数组赋值,0-10
-
- if (judgHas59(a,N)==1) //判断是否有平台
- {
- if (judg1(a,N)==1) //判断最大平台是否唯1
- {
- printf("The biggest platform is 1\n");
- }
- else
- {
- printf("The biggest platform is %d\n",getBiggst(a,N)); //获取最大平台
- }
- }
- else
- {
- printf("No platform");
- }
- system("pause");
- }
-
- int getBiggst(int *a,int n)
- {
- int max=0;
- for (int i=0;i<n;i++)
- {
- int s=0;
- for (int j=0;j<n;j++)
- {
- if(a==a[j])s++;
- }
- if(s>max)max=s; //将当前最大平台赋给max
- }
- return max;
- }
-
- int judg1(int *a,int n)
- {
- for (int i=0;i<n-1;i++)
- {
- if(a==a[i+1])return 0;
- }
- return 1; //表示最大平台为1
- }
-
- int judgHas59(int *a,int n)
- {
- for (int i=0;i<n-1;i++)
- {
- if(a>a[i+1])return 0;
- }
- return 1;
- }</pre><br><br></pre></pre></pre>
|
|