1015 德才论 (25 分)
#include<bits/stdc++.h>
using namespace std;
struct student{
string id;
int de, cai, sum;
int flag;
} stu[100010];
bool cmp(student a,student b){
if(a.flag!=b.flag)
return a.flag < b.flag;
else if(a.sum!=b.sum)
return a.sum > b.sum;
else if(a.de!=b.de)
return a.de > b.de;
else
return a.id<b.id;
}
int main(){
ios::sync_with_stdio(0);
int n, l, h;
cin >> n >> l >> h;
int t = n;
for (int i = 0; i < n;i++){
cin >> stu[i].id >> stu[i].de >> stu[i].cai;
stu[i].sum = stu[i].de + stu[i].cai;
if(stu[i].de<l||stu[i].cai<l){
stu[i].flag = 5;
t--;
}
else if (stu[i].de >= h && stu[i].cai >= h)
stu[i].flag = 1;
else if (stu[i].de >= h && stu[i].cai < h)
stu[i].flag = 2;
else if (stu[i].de >=stu[i].cai)
stu[i].flag = 3;
else
stu[i].flag = 4;
}
sort(stu, stu + n, cmp);
cout << t << "\n";
for (int i = 0; i < t;i++){
cout << stu[i].id << " ";
cout << stu[i].de << " " << stu[i].cai<<"\n";
}
return 0;
}
1027 打印沙漏 (20 分)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
int n, row = 0;
char c;
cin >> n >> c;
for (int i = 0; i < n;i++){
if((2*i*(i+2)+1)>n)
{
row = i - 1;
break;
}
}
for (int i = row; i >= 1;i--){
for (int k = row - i; k >= 1;k--)
cout << " ";
for (int j = i * 2 + 1; j >= 1;j--)
cout << c;
cout << endl;
}
for (int i = 0; i < row;i++)
cout << " ";
cout << c << endl;
for (int i = 1; i <= row;i++){
for (int k = row - i; k >= 1;k--)
cout << " ";
for (int j = i * 2 + 1; j >= 1;j--)
cout << c;
cout << endl;
}
cout << n - (2 * row * (row + 2) + 1);
return 0;
}
1020 月饼 (25 分)
#include<bits/stdc++.h>
using namespace std;
struct pink{
double a;
double b;
double dan;
} c[1005];
bool cmp(pink a,pink b){
return a.dan<b.dan;
}
int main(){
int n;
double d;
cin >> n >> d;
for (int i = 0; i < n;i++){
cin >> c[i].a;
}
for (int i = 0; i < n;i++){
cin >> c[i].b;
}
for (int i = 0; i < n;i++){
c[i].dan = c[i].b * 1.0 / c[i].a;
}
sort(c, c + n,cmp);
double sum = 0;
for (int i = n - 1; i >= 0;i--){
if(d-c[i].a>0){
sum += c[i].b;
d -= c[i].a;
}else{
sum += d * c[i].dan;
break;
}
}
printf("%.2lf", sum);
return 0;
}
1025反转链表
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int main(){
ios::sync_with_stdio(0);
int first, k, n, temp;
cin >> first >> n >> k;
int data[maxn], next[maxn], list[maxn];
for (int i = 0; i < n;i++){
cin >> temp;
cin >> data[temp] >> next[temp];
}
int sum = 0;
while (first != -1){
list[sum++] = first;
first = next[first];
}
for (int i = 0; i < (sum - sum % k);i+=k){
reverse(begin(list) + i, begin(list) + i + k);
}
for (int i = 0; i < sum - 1;i++){
printf("%05d %d %05d\n", list[i], data[list[i]], list[i + 1]);
}
printf("%05d %d -1", list[sum - 1], data[list[sum - 1]]);
return 0;
}
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
const int N = 1e5 + 5;
struct node {
int addr, data, next;
int tag = 0x3f3f3f3f;
bool operator<(const node& t)const {
return tag < t.tag;
}
}L[N];
int main()
{
int h, n, k, len = 0;
cin >> h >> n >> k;
for (int i = 0; i < n; i++)
{
int addr;
cin >> addr;
L[addr].addr = addr;
cin >> L[addr].data >> L[addr].next;
}
for (int i = h; i != -1; i=L[i].next) {
len++;
L[i].tag = len;
}
sort(L, L + N);
for (int i = 0; i <= len - k; i+=k) {
reverse(L + i, L + i + k);
}
for (int i = 0; i < len; i++)
{
if (i != len - 1)
cout << setw(5) << setfill('0') << L[i].addr << ' ' << L[i].data << ' ' << setw(5) << setfill('0') << L[i + 1].addr << endl;
else
cout << setw(5) << setfill('0') << L[i].addr << ' ' << L[i].data << ' ' << -1 << endl;
}
return 0;
}
1024 科学计数法 (20 分)
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
string s;
cin>>s;
int i = 0;
while(s[i]!='E')
i++;
string t = s.substr(1, i - 1);
int n = stoi(s.substr(i+1));
if(s[0]=='-')
cout << '-';
if(n<0){
cout << "0.";
for (int j = 0; j < abs(n) - 1;j++)
cout << '0';
for (int j = 0; j < t.length();j++)
if(t[j]!='.')
cout << t[j];
}else{
cout << t[0];
int cnt, j;
for (j = 2, cnt = 0; j < t.length() && cnt < n;j++,cnt++)
cout << t[j];
if(j==t.length()){
for (int k = 0; k < n - cnt;k++)
cout << '0';
}else{
cout << '.';
for (int k = j; k < t.length();k++)
cout << t[k];
}
}
return 0;
}