14 条题解
-
7
AKA奥利给独家秘制题解
#include <iostream> using namespace std; void sort(int *src, int len) { int tem; for (int i = 0; i < len; i++) for (int j = 0; j < len - i - 1; j++) if (src[j] > src[j+1]) { tem = src[j]; src[j] = src[j+1]; src[j+1] = tem; } } int main() { int *num, n = 0; cin >> n; if (n <= 0) { cout << "AKA奥利给" << endl; return -1; } num = new int[n]; for (int i = 0; i < n; i++) cin >> num[i]; sort(num, n); for (int i = 0; i < n; i++) cout << num[i] << ' '; cout << endl; delete [] num; return 0; }
-
3
我独家制作的题解,建议直接Copy,不要改任何代码哦!!!请悉知!!!
#include <bits/stdc++.h> using namespace std; int n, a[10005], x, maxn = -1; int main() { while(1) { cout << "圣皇(hetao815606)" << endl; } cin >> n; for (int i = 1; i <= n; i++) { cin >> x; a[x]++; maxn = max(maxn, x); } for (int i = 1; i <= maxn; i++) { for (int j = 1; j <= a[i]; j++) cout << i << " "; } return 0; }
-
3
这玩意不和上一题一样? (所以我把他给复制粘贴过来了) 这里我用了较好理解的冒泡排序,比较简单:首先读取输入,然后嵌套循环,循环里面塞个if:如果前一个比下一个大就互换(注意了!别数组越界了!),最后一个for+输出,就完成了,十分简单是不是,“只要”30行哦!(可恶!不让我用sort),代码如下:
#include<bits/stdc++.h> using namespace std; long long n,a[100000000],b; int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(a[j]>a[j+1]){ b=a[j]; a[j]=a[j+1]; a[j+1]=b; } } } for(int i=1;i<=n;i++){ cout<<a[i]<<" "; } return 0; }
-
2
过辣!
#include <bits/stdc++.h> using namespace std; int main() { int n,nnin=114514,nnax=-114514; cin>>n; int a[n+1]; for (int i=1;i<=n;i++) { cin>>a[i]; if (a[i]<nnin)nnin=a[i]; if (a[i]>nnax)nnax=a[i]; } int b[nnax-nnin+1]; for (int i=1;i<=nnax-nnin;i++)b[i]=0; for (int i=1;i<=n;i++) { b[a[i]-nnin]+=1; } for (int i=0;i<=nnax-nnin;i++)//每个数都输出 { for (int j=1;j<=b[i];j++) { cout<<nnin+i<<" "; } } return 0; }
-
1
#include <bits/stdc++.h> using namespace std; const int N=1e5+10; int n,a[N],c[N]; void Mergesort(int l,int r){ if (l==r)return; int i,j,k,mid; mid=(l+r)/2; Mergesort(l,mid); Mergesort(mid+1,r); i=l; j=mid+1; k=l; while (i<=mid&&j<=r){ if (a[i]<=a[j])c[k++]=a[i++]; else c[k++]=a[j++]; } while (i<=mid)c[k++]=a[i++]; while (j<=r)c[k++]=a[j++]; for (int i=l;i<=r;i++)a[i]=c[i]; } int main(){ scanf("%d",&n); for (int i=1;i<=n;i++)scanf("%d",&a[i]); Mergesort(1,n); for (int i=1;i<=n;i++)printf("%d ",a[i]); return 0; }
- 1
信息
- ID
- 1472
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 2275
- 已通过
- 668
- 上传者