201503-1
设置了矩阵数组int a[1005][1005],在dev c++上运行会报错,因为数组太大了,但没想到提交直接满分过了。
懒得想高效,占内存少的解法了…
int main() {
cin>>n>>m;
int a[1000][1000];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>a[i][j];
}
}
for(int i=m-1;i>=0;i--){
for(int j=0;j<n;j++){
cout<<a[j][i]<<' ';
}
cout<<endl;
}
return 0;
}
201503-2
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include <bits/stdc++.h>
#include "sstream"
using namespace std;
#define N 1005
int n,m;
struct node {
int x;
int num;
};
node edge[1005];
int cmpfunc (const void * a, const void * b)
{
struct node *c = (node *)a;
struct node *d = (node *)b;
if(c->num != d->num) return d->num - c->num;
else return c->x - d->x;
}
int main() {
cin>>n;
int a[1005];
int x;
memset(a,0,sizeof(a));
for(int i=0;i<n;i++){
cin>>x;
a[x]++;
edge[x].num=a[x];
edge[x].x=x;
}
qsort(edge,1005,sizeof(edge[0]),cmpfunc);
for(int i=0;i<n&&edge[i].num;i++){
cout<<edge[i].x<<' '<<edge[i].num<<endl;
}
return 0;
}
//
今天偷懒去游泳happy了
不想面对日后参与项目的打工生活QAQ