1014 福尔摩斯的约会 (20 分)
分析:
一道字符串处理,照着要求来就行
代码:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
string a, b, c, d;
cin >> a >> b >> c >> d;
char t[2];
int pos, i = 0, j = 0;
while(i < a.length() && i < b.length())
{
if (a[i] == b[i] && (a[i] >= 'A' && a[i] <= 'G'))
{
t[0] = a[i];
break;
}
i++;
}
i = i + 1;
while (i < a.length() && i < b.length())
{
if (a[i] == b[i] && ((a[i] >= 'A' && a[i] <= 'N') || isdigit(a[i])))
{
t[1] = a[i];
break;
}
i++;
}
while (j < c.length() && j < d.length())
{
if (c[j] == d[j] && isalpha(c[j]))
{
pos = j;
break;
}
j++;
}
string week[7] = {"MON ", "TUE ", "WED ", "THU ", "FRI ", "SAT ", "SUN "};
int m = isdigit(t[1]) ? t[1] - '0' : t[1] - 'A' + 10;
cout << week[t[0]-'A'];
printf("%02d:%02d", m, pos);
return 0;
}
1015 德才论 (25 分)
分析:
把及格的学生分为四类,每一类再分别排序,一类一类的输出。注意cmp函数的写法。
代码:
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef struct student
{
int num;
int moral;
int capability;
}student;
bool cmp(student x,student y)
{
if(x.capability+x.moral!=y.capability+y.moral)
return x.capability+x.moral>y.capability+y.moral;
else if(x.moral!=y.moral)
return x.moral>y.moral;
else
return x.num<y.num;
}
int main()
{
int N,L,H;
cin>>N>>L>>H;
int total=N;
vector<student> stu[4];//一共四类学生
for(int i=0;i<N;i++)
{
student a;
cin>>a.num>>a.moral>>a.capability;
if(a.moral<L||a.capability<L)
total--;
else if(a.moral>=H&&a.capability>=H)
stu[0].push_back(a);
else if(a.moral>=H&&a.capability<H)
stu[1].push_back(a);
else if(a.moral<H&&a.capability<H&&a.moral>=a.capability)
stu[2].push_back(a);
else if(a.moral>=L&&a.capability>=L)
stu[3].push_back(a);
}
printf("%d\n",total);
for(int i=0;i<4;i++)
{
sort(stu[i].begin(),stu[i].end(),cmp);
for(int j=0;j<stu[i].size();j++)
{
cout<<stu[i][j].num<<" "<<stu[i][j].moral<<' '<<stu[i][j].capability<<endl;
}
}
}