从零单排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[ ...
随机推荐
- coroutine
在脚本语言中,coroutine 不是个新鲜词汇,比如 lua 内建 coroutine,python中的greenlet,但在C程序中,并不是太常见. windows 下有 fiber,相关函数为 ...
- hdu 1078(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 //dp[i][j]表示从点i,j处开始能获得的最多cheese #include <io ...
- PS快捷键大全
一.工具箱(多种工具共用一个快捷键的可同时按[Shift]加此快捷键选取) 矩形.椭圆选框工具 [M] 移动工具 [V] 套索.多边形套索.磁性套索 [L] 魔棒工具 [W] 裁剪工具 [C ...
- db2 for linux
https://www6.software.ibm.com/sdfdl/v2/regs2/db2pmopn/db2_v101/expc/Xa.2/Xb.aA_60_-idYiSFeSuWlF5-w4v ...
- 高级new创建
myclass *p = new(pcathe)myclass[10];//限定区域分配内存,覆盖模式,可以避免内存泄漏 #include <iostream> class myclass ...
- H264源码分析(四)
sub_mb_pred( mb_type ) { for( mbPartIdx = 0; mbPartIdx < 4; mbPartIdx++ ) ...
- poj 2513 Colored Sticks (trie 树)
链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 ...
- poj 3764 The xor-longest Path(字典树)
题目链接:poj 3764 The xor-longest Path 题目大意:给定一棵树,每条边上有一个权值.找出一条路径,使得路径上权值的亦或和最大. 解题思路:dfs一遍,预处理出每一个节点到根 ...
- Android之ActionBar学习
关于那个问题:是关于如何生成如下图所示之ActionBar效果: 其实就在官网上就有答案,自己疏忽再加上资料繁多.寻了许久,经过指点.终于找到: To enable split action bar, ...
- day10_python学习笔记_chapter13_面向对象编程
1. class NewClass(parent): def .... 如果没有父类, 则默认继承object类 2. 类属性访问(类似java中的静态属性和方法)直接用类名.属性名, 在python ...