链接
7-12 CPA招新Ⅱ (25 分)
新学期开始啦,我们CPA是2019年6月成立的,创建时有20位元老。现在需要招新啦,每年新学期社团服务中心会组织百团大战。我们CPA迎来第一次招新,我们很期待迎来新成员。
每天都有元老去招新,每招到一个萌新,招新人会在纸上写一个大写字母。CPA共有竞赛部、宣传部、办公部、组织部四个部门。我们规定A代表竞赛部(Competition department),B代表宣传部(Propaganda Department)、C代表办公部(Office)、D组织部(Organization Department)。社团招新后需要统计每一个部门有多少人?有一天会长突然来了,需要你给他一份部门人员名单,名单需要根据人数从大到小排序的,聪明的你会直接写一个程序给会长,让他直接使用程序排序。
输入格式:
输入一行字符串,字符串长度不大于10000。
输出格式:
如果人数相同,按照字典序从小到大排序,每输出一个部门换行。
输入样例:
AABBCCCDDAA
输出样例:
Competition department 4 people!
Office 3 people!
Organization Department 2 people!
Propaganda Department 2 people!
备注
也许有人调皮不止ABCD四个字符,真实人数以ABCD为准。
rnm的PTA真恶心,意思就是会出现空格
所以scanf肯定不行,getf只能用c的格式交,字符串只能用stirng,所以用不来sort,选冒泡排序;
ac代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string ss;
struct node
{
char a[110];
char b;
int c;
}l[10010];
int main()
{
//l[1].a="Competition department";
strcpy(l[1].a,"Competition department");
l[1].b='A';
//l[2].a="Propaganda Department";
strcpy(l[2].a,"Propaganda Department");
l[2].b='B';
//l[3].a="Office";
strcpy(l[3].a,"Office");
l[3].b='C';
// l[4].a="Organization Department";
strcpy(l[4].a,"Organization Department");
l[4].b='D';
//gets(ss); pta里这样写必须用c语言形式交才能编译成功
getline(cin,ss);
for(int i=0;i<ss.length();i++)
{
for(int j=1;j<=4;j++)
{
if(l[j].b==ss[i])
l[j].c++;
}
}
for(int i=1;i<=3;i++)//冒泡排序
{
for(int j=1;j<=3;j++)
{
if(l[j].c<l[j+1].c)
swap(l[j],l[j+1]);
else if(l[j].c==l[j+1].c&& ( strcmp(l[j].a,l[j+1].a)>0 ) )//字符串排序
swap(l[j],l[j+1]);
}
}
for(int i=1;i<=4;i++)
cout<<l[i].a<<" "<<l[i].c<<" "<<"people!"<<endl;
}