A:通讯录编排
#include <bits/stdc++.h>
using namespace std;
struct Person
{
string tzoj;
string phone;
string A;
int y,m,d;
}a[101];
bool cmp(Person a,Person b)
{
if(a.A!=b.A)
return a.A<b.A;
if(a.m!=b.m)
return a.m<b.m;
if(a.d!=b.d)
return a.d<b.d;
return a.tzoj<b.tzoj;
}
int main()
{
int n;
cin>>n;
char c;
for(int i;i<n;i++)
{
cin>>a[i].tzoj>>a[i].phone>>a[i].A>>a[i].y>>c>>a[i].m>>c>>a[i].d;
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(!cmp(a[j],a[j+1]))
swap(a[j],a[j+1]);
}
}
for(int i=0;i<n;i++)
{
cout<<a[i].tzoj<<" "<<a[i].phone<<" "<<a[i].A<<" "<<a[i].y<<c<<a[i].m<<c<<a[i].d;
cout<<endl;
}
return 0;
}
B:贫富差距
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
while(cin>>n)
{
int *a[10001];
for(int i = 0;i<n;i++)
{
int m;
cin>>m;
a[i] = new int[m+3];
a[i][1] = i+1;
a[i][2] = m;
a[i][0] = 0;
for(int j = 0;j<m;j++)
{
cin>>a[i][j+3];
a[i][0] += a[i][j+3];
}
}
for(int i = 0;i<n-1;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(a[j][0]<a[j+1][0] || a[j][0]==a[j+1][0]&&a[j][1]>a[j+1][1])
{
swap(a[j],a[j+1]);
}
}
}
for(int i = 0;i<n;i++)
{
if(a[i][0]!=0)
{
cout<<a[i][1]<<":";
for(int j = 0;j<a[i][2];j++)
{
cout<<" "<<a[i][j+3];
}
cout<<endl;
}
}
cout<<endl;
}
return 0;
}
C:C实验:变量交换函数
#include <stdio.h>
void Swap(int* a,int* b)
{
int t= *a;
*a = *b;
*b = t;
}
int main()
{
int a, b;
while(scanf("%d%d", &a, &b)!=EOF)
{
Swap(&a, &b);
printf("%d %d\n", a, b);
}
return 0;
}
D:C实验:结构体定义和使用
#include<stdio.h>
struct Student
{
char Name[21];
int score;
};
int Input(struct Student *p)
{
scanf("%s%d", p->Name,&p->score);
}
void Print(struct Student s)
{
printf("%s %d\n", s.Name, s.score);
}
int main()
{
struct Student s;
while(Input(&s)!=EOF)
{
Print(s);
}
return 0;
}
E:开门人和关门人
#include <bits/stdc++.h>
using namespace std;
struct Person
{
string id,s,e;
}a[101];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i].id>>a[i].s>>a[i].e;
int mn = 0,mx = 0;
for(int i=1;i<n;i++)
{
if(a[i].s<a[mn].s)
mn = i;
if(a[i].e>a[mx].e)
mx = i;
}
cout<<a[mn].id<<" "<<a[mx].id<<endl;
}
return 0;
}
F:考试座位号
#include <bits/stdc++.h>
using namespace std;
struct A
{
string id;
int see;
}a[1001];
int main()
{
int n;
cin>>n;
while(n--)
{
A t;
int x,y;
cin>>t.id>>x>>t.see;
a[x] = t;
}
cin>>n;
while(n--)
{
int x;
cin>>x;
cout<<a[x].id<<" "<<a[x].see<<endl;
}
return 0;
}
G:德才论
#include <bits/stdc++.h>
using namespace std;
const int N=100000;
struct A
{
string id;
int d;
int c;
int t;
}a1[N],a2[N],a3[N],a4[N];
int n1 = 0,n2 = 0,n3 = 0,n4 = 0;
bool cmp(const A &a,const A &b)
{
if(a.t!=b.t)
return a.t>b.t;
if(a.d!=b.d)
return a.d>b.d;
return a.id<b.id;
}
int main()
{
int n,l,h;
cin>>n>>l>>h;
while(n--)
{
A x;
cin>>x.id>>x.d>>x.c;
x.t = x.d+x.c;
if(x.d>=h && x.c>=h)
a1[n1++] = x;
else if(x.d>=h && x.c>=l)
a2[n2++] = x;
else if(x.d>=l && x.c>=l && x.d>=x.c)
a3[n3++] = x;
else if(x.d>=l && x.c>=l)
a4[n4++] = x;
}
sort(a1,a1+n1,cmp);
sort(a2,a2+n2,cmp);
sort(a3,a3+n3,cmp);
sort(a4,a4+n4,cmp);
cout<<n1+n2+n3+n4<<endl;
for(int i=0;i<n1;i++)
cout<<a1[i].id<<" "<<a1[i].d<<" "<<a1[i].t-a1[i].d<<endl;
for(int i=0;i<n2;i++)
cout<<a2[i].id<<" "<<a2[i].d<<" "<<a2[i].t-a2[i].d<<endl;
for(int i=0;i<n3;i++)
cout<<a3[i].id<<" "<<a3[i].d<<" "<<a3[i].t-a3[i].d<<endl;
for(int i=0;i<n4;i++)
cout<<a4[i].id<<" "<<a4[i].d<<" "<<a4[i].t-a4[i].d<<endl;
return 0;
}
H:QQ群成员排名
#include <bits/stdc++.h>
using namespace std;
struct QQ
{
string name;
int score;
int flag;
}a[2001];
bool cmp(const QQ &a, const QQ &b)
{
if(a.flag!=b.flag)
return a.flag>b.flag;
if(a.score!=b.score)
return a.score>b.score;
return a.name<b.name;
}
int main()
{
int n;
while(cin>>n)
{
for(int i=0;i<n;i++)
cin>>a[i].name>>a[i].score>>a[i].flag;
sort(a,a+n,cmp);
for(int i=0;i<n;i++)
{
cout<<a[i].name<<" "<<a[i].score<<" "<<a[i].flag<<endl;
}
}
return 0;
}
I:C实验:n个元素之和
#include<stdio.h>
void GetValue(int *p, int a[] )
{
scanf("%d",p);
int i;
for(i=0;i<*p;i++)
scanf("%d",&a[i]);
}
int main()
{
int a[10], n, i, s = 0;
GetValue(&n, a);
for(i=0;i<n;i++)
s += a[i];
printf("%d\n", s);
return 0;
}