从零单排PAT1015,1016,1017,1018
1015德才论 题目要求:
输入格式:
输入第1行给出3个正整数,分别为:N(<=105),即考生总数。L(>=60)。为录取最低分数线,即德分和才分均不低于L的考生才有资格被考虑录取;H(<100)。为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于H,可是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者。按总分排序,但排在第二类考生之后;其它达到最低线L的考生也按总分排序。但排在第三类考生之后。
随后N行,每行给出一位考生的信息,包含:准考证号、德分、才分,当中准考证号为8位整数。德才分为区间[0, 100]内的整数。数字间以空格分隔。
输出格式:
输出第1行首先给出达到最低分数线的考生人数M,随后M行,每行依照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分同样时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
输入例子:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
输出例子:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
cout流输入,由于速度慢。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> using namespace std; typedef struct student{
string studentID;
int caiScore;
int deScore;
}Student; bool compare(Student stu1,Student stu2)
{
if(stu1.caiScore + stu1.deScore != stu2.caiScore + stu2.deScore) //不相等时。比总分
{
return stu1.caiScore + stu1.deScore > stu2.caiScore + stu2.deScore;
}
else if(stu1.deScore != stu2.deScore ) //总分相等时,比德
{
return stu1.deScore > stu2.deScore;
}
else
return stu1.studentID < stu2.studentID; } inline void print(Student stu)
{
//cout << stu.studentID << " " << stu.deScore << " " << stu.caiScore << endl;
printf("%s %d %d\n",stu.studentID.c_str(),stu.deScore,stu.caiScore);
} int main()
{
char id[10];
Student stu ;
int studentNumber = 0,minScore = 0,maxScore = 0;
scanf("%d %d %d",&studentNumber,&minScore,&maxScore);
vector<Student> student[4];
for(int i = 0;i<studentNumber ;i++)
{
scanf("%s %d %d",id,&stu.deScore,&stu.caiScore);
stu.studentID.assign(id);
if(stu.deScore >= minScore && stu.caiScore >= minScore)
{
if(stu.deScore >= maxScore) //DC >=H
{
if(stu.caiScore >= maxScore)
{
student[0].push_back(stu); //符合要求才存入
}
else
{
student[1].push_back(stu);
}
}
else
{
if(stu.deScore >= stu.caiScore)
{
student[2].push_back(stu);
}
else
{
student[3].push_back(stu);
}
}
}
}
sort(student[0].begin(),student[0].end(),compare);
sort(student[1].begin(),student[1].end(),compare);
sort(student[2].begin(),student[2].end(),compare);
sort(student[3].begin(),student[3].end(),compare); printf("%d\n",student[0].size()+student[1].size()+student[2].size()+student[3].size()); for_each(student[0].begin(),student[0].end(),print);
for_each(student[1].begin(),student[1].end(),print);
for_each(student[2].begin(),student[2].end(),print);
for_each(student[3].begin(),student[3].end(),print); system("pause");
return 0;
}
正整数A的“DA(为1位整数)部分”定义为由A中全部DA组成的新整数PA。
比如:给定A = 3862767。DA = 6,则A的“6部分”PA是66,由于A中有2个6。
现给定A、DA、B、DB,请编敲代码计算PA + PB。
输入格式:
输入在一行中依次给出A、DA、B、DB。中间以空格分隔。当中0 < A, B < 1010。
输出格式:
在一行中输出PA + PB的值。
输入例子1:
3862767 6 13530293 3
输出例子1:
399
输入例子2:
3862767 1 13530293 8
输出例子2:
0
解答思路:
#include <iostream>
#include <string> using namespace std;
int main()
{
string a,b;
int A,B;
cin >> a >> A >> b >> B;
int lenth_a = a.size();
int lenth_b = b.size();
int Acount = 0,Bcount = 0;
for(int i = 0;i<lenth_a;i++)
{
if(a[i] - '0' == A)
Acount ++ ;
}
for(int i = 0;i<lenth_b;i++)
{
if(b[i] - '0' == B)
Bcount ++;
}
int temp1 = 0,temp2 = 0;
for(int i = 0;i<Acount;i++)
{
int temp = A;
for(int j = 0;j<i;j++)
{
temp = temp * 10;
}
temp1 = temp1 + temp; //直接计算出找到相应的值和位数的值
}
for(int i = 0;i<Bcount;i++)
{
int temp = B;
for(int j = 0;j<i;j++)
{
temp = temp * 10;
}
temp2 = temp2 + temp;
}
cout << temp1 + temp2 << endl;
system("pause");
return 0;
}
本题要求计算A/B,当中A是不超过1000位的正整数。B是1位正整数。
你须要输出商数Q和余数R。使得A = B * Q + R成立。
输入格式:
输入在1行中依次给出A和B,中间以1空格分隔。
输出格式:
在1行中依次输出Q和R。中间以1空格分隔。
输入例子:
123456789050987654321 7
输出例子:
17636684150141093474 3
解题思路:
#include <iostream>
#include <string> using namespace std;
int main()
{
string A,Q;
int B,R = 0;
cin >> A >> B;
int lenth = A.size();
int temp = 0; //用于存储上一位的余数用于存储下一位的
int temp1 = 0; //实际每一次的被除数
for(int i = 0;i<lenth;i++)
{
temp = R * 10;
temp1 = temp + A[i] - '0';
Q += temp1/B + '0';
R = temp1%B;
}
if(Q[0] == '0' && Q.size() > 1)
{
//Q.erase(Q[0],Q.size());//为什么会数组越界
Q.erase(Q.begin());
}
cout << Q << " " << R <<endl;
system("pause");
return 0;
}
现给出两人的交锋记录,请统计两方的胜、平、负次数,而且给出两方分别出什么手势的胜算最大。
输入格式:
输入第1行给出正整数N(<=105),即两方交锋的次数。
随后N行,每行给出一次交锋的信息,即甲、乙两方同一时候给出的的手势。
C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方。第2个代表乙方,中间有1个空格。
输出格式:
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。假设解不唯一,则输出按字母序最小的解。
输入例子:
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
输出例子:
5 3 2
2 3 5
B B
解题思路:
我却一直通只是,后来一想才发现,甲输的手势不是乙胜利的手势,所以又一次改动參数。
逻辑计较简单,可是不能弄错,最简单也是最搓的办法多设标志位计数。
#include <iostream> using namespace std;
char getY(int a,int b,int c)//a = B,b = C ,C = J
{
if(a >= b && a >= c)
return 'B';
if(b > a && b >= c)
return 'C';
if(c > a && c > b)
return 'J';
} int main()
{
long int N;
int countY = 0,countP = 0,countS = 0;//记录赢平输的个数
int YC = 0 ,YJ = 0,YB = 0,SC = 0,SJ = 0,SB = 0;
cin >> N;
char A,B;
for(int i = 0;i < N;i++)
{
cin >> A >> B;
if(A == 'C')//出锤子的情况
{
if(B == 'C') //平
countP ++;
else if(B == 'J')
{ countY ++; YC ++; }//甲锤子胜场+1
else
{ countS ++; SC ++; }//乙布胜场+1
}
else if(A == 'J')//出剪刀的情况
{
if(B == 'J') //平
countP ++;
else if(B == 'B')
{ countY ++; YJ ++; }//甲剪刀胜场+1
else
{ countS ++; SJ ++; }//乙锤子胜场+1
}
else //出布的情况
{
if(B == 'B')
countP ++;
else if(B == 'C')
{ countY ++; YB ++; }//甲布胜场+1
else
{ countS ++; SB ++; }//乙剪刀胜场+1
}
}
cout << countY << " " << countP << " " << countS <<endl;
cout << countS << " " << countP << " " << countY <<endl;
cout << getY(YB,YC,YJ) << " " << getY(SC,SJ,SB) <<endl;
//cout << "A" << " " << "A" <<endl;
system("pause");
return 0;
}
从零单排PAT1015,1016,1017,1018的更多相关文章
- 从零单排之玩转Python安全编程(II)
转自:http://www.secpulse.com/archives/35893.html 都说Python大法好,作为一名合格的安全从业人员,不会几门脚本语言都不好意思说自己是从事安全行业的. 而 ...
- HDU4870_Rating_双号从零单排_高斯消元求期望
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4870 原题: Rating Time Limit: 10000/5000 MS (Java/Other ...
- 从零单排Linux – 3 – 目录结构
从零单排Linux – 3 – 目录结构 1.FHS标准(filesystem hierarchy standard) why? –> 为了规范,还有为了linux的发展 重点 –> 规范 ...
- 从零单排Linux – 2 – 目录权限
从零单排Linux – 2 – 目录权限 1.sync 讲内存数据跟新到硬盘中 2.执行等级init a: run level 0:关机 b: run level 3:纯命令模式 c:run leve ...
- 从零单排Linux – 1 – 简单命令
从零单排Linux – 1 – 简单命令 Posted in: Linux 从零单排Linux – 1 一.Linux的简单命令: 1.忘记root密码: 读秒时按任意键进入 – e – ↓选择第二个 ...
- JAVA从零单排之前因
本人,男,21岁,普通院校本科,计算机专业.大学之前对计算机编程没有一点涉及.大学学计算机专业也是个偶然.因为当初高考的成绩不好,结果都是我父亲帮我报的学校和专业. 上了大学之后,大一都是在新奇中度过 ...
- Unity3D游戏开发从零单排(四) - 制作一个iOS游戏
提要 此篇是一个国外教程的翻译,尽管有点老,可是适合新手入门. 自己去写代码.debug,布置场景,能够收获到非常多.游戏邦上已经有前面两部分的译文,这里翻译的是游戏的最后一个部分. 欢迎回来 在第一 ...
- 从零单排学Redis【铂金二】
前言 只有光头才能变强 好的,今天我们要上[铂金二]了,如果还没有上铂金的,赶紧先去蹭蹭经验再回来(不然不带你上分了): 从零单排学Redis[青铜] 从零单排学Redis[白银] 从零单排学Redi ...
- 从零单排学Redis【铂金一】
前言 只有光头才能变强 好的,今天我们要上铂金段位了,如果还没经历过青铜和白银和黄金阶段的,可以先去蹭蹭经验再回来: 从零单排学Redis[青铜] 从零单排学Redis[白银] 从零单排学Redis[ ...
随机推荐
- Spring+Spring MVC+MyBatis
Spring+Spring MVC+MyBatis 目录 一.新建一个基于Maven的Web项目 二.创建数据库与表 三.添加依赖包 四.新建POJO实体层 五.新建MyBatis SQL映射层 六. ...
- sshd服务---暴力破解应对策略
sshd服务暴力破解步骤 sshd暴力破解方法 防止暴力破解调优 1. 变更默认端口 2. 变更root用户 3. 日志监控-->防止暴力破解(fail2ban应用) fail2ban详解 在初 ...
- Windows 10开发基础——文件、文件夹和库(一)
原文:Windows 10开发基础--文件.文件夹和库(一) 主要内容: 1.枚举查询文件和文件夹 2.文本文件读写的三种方法——创建写入和读取文件 3.获得文件的属性 枚举查询文件和文件夹 先了解一 ...
- js调用打印机
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- POJ——字符串插入
2:字符串插入 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 有两个字符串str和substr,str的字符个数不超过10,substr的字符个数为3.( ...
- iterm快捷键及操作技巧(附Linux快捷键)
标签操作 新建标签:command + t 关闭标签:command + w 切换标签:command + 数字 command + 左右方向键 切换全屏:command + enter 查找:com ...
- Spring、整合Spring+JDBC
首先引入Spring包和JDBC所使用到的包: 配置beans.xml步骤: 1.配置dataSource的属性 2.将DataSource交给DataSourceTransactionManager ...
- Android UI ActionBar功能-在 Action Bar 上添加按钮
在ActionBar上添加按钮实现某些功能最常见的Application的功能如:在ActionBar上添加一个搜索按钮: 首先官方文档说明:http://wear.techbrood.com/tra ...
- REST和JAX-RS相关知识介绍
REST REpresentational State Transfer:代表性状态传输.具象状态传输 REST定义了应该如何正确地使用Web标准,例如HTTP和URI.REST并非标准,而是一种开发 ...
- bootstrap-js(4)标签页
实例 标签页(Tab)在 Bootstrap 导航元素 一章中介绍过.通过结合一些 data 属性,您可以轻松地创建一个标签页界面. 通过这个插件您可以把内容放置在标签页或者是胶囊式标签页甚至是下拉菜 ...