问题 I: 用品
题目描述
只有一行,即为:把小写字母改成相应的大写字母,其他字符依照原有顺序不变的字符串。
已知:笔记本每本2元,铅笔每支0.5元,橡皮每块0.8元,圆珠笔每支2.5元。
现在请你计算一下:1) 每位同学合计花了多少元(如果有小数,最后结果下取整即可)?
2)N名同学购买学习用品平均花费的钱数是多少元(如果有小数,最后结果下取整即可)?
3)统计N名同学中哪些同学购买学习用品的花费低于平均花费(注意是低于实际平均花费,并非上面的显示值)?
输入
第一行有一个整数N,表示有N名同学,已知2≤N≤10;
以下有5*N行数据,每5行代表一个人的信息记录(包括学生的姓名及购买4种学习用品的数量,其中4种学习用品的数量都为不大于50的整数)。
输出
共有若干行:
前N行:每行一个数据是每位同学合计所花的钱数(按照取整显示);
之后的一行:是N名同学平均花费的钱数(每人花费取整后总和再平均);
最后若干行:每行一个数据是N名同学中低于平均花费的学生姓名(低于低于实际平均花费的人名)。
按输入顺序输出
样例输入 Copy
3 zhangfang 5 10 6 3 lihao 8 12 2 3 wanghong 6 8 4 3
样例输出 Copy
27 31 26 28 zhangfang wanghong
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
typedef struct
{
string na;
double a,b,c,d;
int p;
}TX;
TX w[15];
//狗日的垃圾题目说一套做一套
//写的是低于实际平均花费 结果数据又要人用ban掉小数位的来比较
int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>w[i].na>>w[i].a>>w[i].b>>w[i].c>>w[i].d;
w[i].p = floor(w[i].a*2.0 + w[i].b*0.5 + w[i].c*0.8 + w[i].d*2.5);
cout<<w[i].p<<endl;
}
double sum = 0;
for(int i = 1; i <= n; i++)
{
sum+=w[i].p;
}
int y = floor(sum / (double)n);
cout<<y<<endl;
for(int i = 1; i <= n; i++)
{
if(w[i].p < y)
{
cout<<w[i].na<<endl;
}
}
return 0;
}
问题 L: 乐乐的数字
题目描述
乐乐做完数学作业,突发奇想定义了一种新的数:乐乐数。乐乐把n个数排成一行,一个数的“乐乐数”是指:在这个数的左边且比它小的数中最靠近它(即最靠右)的那个数。依次给出这n个数,请求出所有这n个数相对应的“乐乐数”。
输入
第一行是一个正整数n,表示一共有多少个数。
第二行有n个用空格隔开的正整数,它们从左至右给出了数列中的n个数。这些数保证小于231。
输出
输出一行用空格隔开的n个数。
这些数对应于输入数据中的数的“乐乐数”。如果输入中某个数没有“乐乐数”(即它左边的数都不比它小),请输出0。
样例输入 Copy
7 3 1 2 7 6 7 4
样例输出 Copy
0 0 1 2 2 6 2
提示
对于80%的数据,n≤10000;
对于100%的数据,n≤200000。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
long long a[200005] = {0};
long long b[200005] = {0};
//为了不T 用空间换时间
//借助上一个位置的乐乐数来削减这一个位置乐乐数的寻找消耗
int main()
{
ios::sync_with_stdio(false),cin.tie(NULL);
int n;
cin>>n;
a[0] = 0;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
if(a[i - 1] < a[i])
{
b[i] = a[i - 1];
}
else
{
if(b[i - 1] < a[i])
{
b[i] = b[i - 1];
}
else
{
int j = i - 2;
while(a[j] >= a[i] && b[j] >= a[i])
{
j--;
}
if(a[j] < a[i])
{
b[i] = a[j];
}
if(b[j] < a[i])
{
b[i] = b[j];
}
}
}
cout<<b[i];
if(i == n) cout<<endl;
else cout<<' ';
}
return 0;
}