标签:时间 stream tns else 文件中 提高 enter scanf 提交
1 #include <algorithm> 2 #include <iostream> 3 #include <string.h> 4 int num[1005]; 5 using namespace std; 6 int main() 7 { 8 int n,i = 0,sum; 9 int temp[5][1005],dp[5] = {90,80,70,60,0}; 10 memset(temp,0,sizeof(temp)); 11 cin>>sum; 12 for(;i < sum;i++) 13 { 14 cin>>num[i]; 15 for(int j = 0;j < 5;j++) 16 { 17 if(num[i] >= dp[j]) 18 { 19 temp[j][++temp[j][0]] = num[i]; 20 break; 21 } 22 } 23 } 24 int maxn = 0,maxl = 0; 25 for(int t = 0;t < 5;t++) 26 { 27 cout<<temp[t][0]<<" ";//输出每个等级的人数 28 if(maxn < temp[t][0]) 29 { 30 maxn = temp[t][0]; 31 maxl = t; 32 } 33 } 34 cout<<endl<<maxn<<endl; 35 sort(temp[maxl]+1,temp[maxl]+temp[maxl][0]+1); 36 for(int t = temp[maxl][0];t >= 1;t--) 37 cout<<temp[maxl][t]<<" "; 38 return 0; 39 }
1 #include<stdio.h> 2 int main(){ 3 int n; 4 int a=1,b=1,c=1,d=1,e=1; 5 scanf("%d",&n); 6 int score[n]; 7 int a1[5][n]; 8 for(int i=0;i<5;i++){ 9 a1[i][0]=0; 10 } 11 for(int i=0;i<n;i++){ 12 scanf("%d",&score[i]); 13 if(score[i]>=90){ 14 a1[0][a]=score[i]; 15 a1[0][0]++; 16 a++; 17 } 18 else if(score[i]>=80 && score[i]<90){ 19 a1[1][b]=score[i]; 20 a1[1][0]++; 21 b++; 22 } 23 else if(score[i]>=70 && score[i]<80){ 24 a1[2][c]=score[i]; 25 a1[2][0]++; 26 c++; 27 } 28 else if(score[i]>=60 && score[i]<70){ 29 a1[3][d]=score[i]; 30 a1[3][0]++; 31 d++; 32 } 33 else if(score[i]<60){ 34 a1[4][e]=score[i]; 35 a1[4][0]++; 36 e++; 37 } 38 } 39 printf("%d %d %d %d %d\n",a1[0][0],a1[1][0],a1[2][0],a1[3][0],a1[4][0]); 40 41 /*对各个等级人数进行冒泡降序*/ 42 for(int i=0; i<5-1; i++){ 43 for(int j=0; j<5-1-i; j++){ 44 /*降序*/ 45 if(a1[j][0]<a1[j+1][0]){ 46 int t = a1[j][0]; 47 a1[j][0] = a1[j+1][0]; 48 a1[j+1][0] = t; 49 } 50 } 51 } 52 printf("%d\n",a1[0][0]); 53 for(int i=1;i<=a1[0][0];i++){ 54 printf("%d ",a1[1][i]); 55 } 56 }
标签:时间 stream tns else 文件中 提高 enter scanf 提交
原文地址:http://www.cnblogs.com/panweiwei/p/6443834.html