fork(1) download
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. int main() {
  4. int n,count,t,temp=0;
  5. scanf("%d",&n);
  6. int a[n],b[30]={0};
  7. for(int i=0;i<n;i++)
  8. scanf("%d ",&a[i]);
  9. for(int i=0;i<n-1;i++)
  10. {
  11. if(a[i]<=a[i+1])
  12. temp=1;
  13. else
  14. {
  15. temp=0;
  16. break;
  17. }
  18.  
  19.  
  20. }
  21. if(temp==1)
  22. {
  23. printf("%d",n);
  24. exit(0);
  25. }
  26. for(int j=0;j<n/2;j++)
  27. { count=1;
  28. for(int k=j+1;k<n/2;k++)
  29. {
  30. if(a[j]<=a[k])
  31. {count++;
  32. b[j]=count;
  33. }
  34. else
  35. {
  36. break;
  37. }
  38. }
  39. }
  40. for(int p=n/2;p<n;p++)
  41. { count=1;
  42. for(int q=p+1;q<n;q++)
  43. {
  44. if(a[p]<=a[q])
  45. {
  46. count++;
  47. b[p]=count;
  48. }
  49. else
  50. {
  51.  
  52. break;
  53. }
  54. }
  55. }
  56.  
  57. for(int y=0;y<n;y++)
  58. { printf("%d",b[y]);
  59. if(b[y]>=b[y+1])
  60. {
  61. t=b[y];
  62. b[y]=b[y+1];
  63. b[y+1]=t;
  64. }
  65. }
  66. printf("%d",b[n-1]);
  67.  
  68.  
  69.  
  70.  
  71. }
  72.  
  73.  
Success #stdin #stdout 0s 4360KB
stdin
8
11 12 1 2 13 14 3 4
stdout
222222220