02 2020 档案

摘要:Shopping 思路:这道题很明显使用容器,此时我们来判断使用什么容器,这道题涉及了不同数据类型的保存,故使用map,正常使用map进行数据的保存,最后利用迭代器比较大小,最后输出。 代码: #include<iostream> #include<string> #include<map> usi 阅读全文
posted @ 2020-02-26 22:24 PCDL&TIPO 阅读(196) 评论(0) 推荐(0)
摘要:产生冠军 思路:这道题,先读题分析,我们可以知道,为了产生冠军,会进行两两比赛,让我们寻找一种办法判断是否产生冠军,既然提到了方法,那么意味着,必有一个简便方法来判断是否有冠军,因为,两两发生比赛,一个人可能产生多场比赛,但是,我们换成一下思路,什么是冠军,冠军即使唯一没输过的人,所以,当全部人数- 阅读全文
posted @ 2020-02-26 21:54 PCDL&TIPO 阅读(264) 评论(0) 推荐(0)
摘要:士兵队列训练问题 思路:这道题是属于容器的题,当我们读到题时,我们先想一下,这个适合用什么。我们可以直接读到,一直以1~2或1~3报数的方式,删除容器中的元素,此时我们就可以确定,我们使用list更加方便。此时,大框架已经基本完成,我们只需要模拟整个过程即可。 代码: #include<iostre 阅读全文
posted @ 2020-02-26 21:45 PCDL&TIPO 阅读(164) 评论(0) 推荐(0)
摘要:ACboy needs your help again! 思路:分两种容器,一个先进先出,一个先进后出,显然一个队列,一个栈,分好情况就行 代码: #include<iostream> #include<queue> #include<stack> using namespace std; int 阅读全文
posted @ 2020-02-23 15:08 PCDL&TIPO 阅读(204) 评论(0) 推荐(0)
摘要:Text Reverse 思路:这道题就是一个字符串反转的问题,可以考虑使用栈的性质,先进后出,来完成这道题 代码: #include<iostream> #include<stack> using namespace std; int main(){ int n; char ch; while ( 阅读全文
posted @ 2020-02-23 15:05 PCDL&TIPO 阅读(152) 评论(0) 推荐(0)
摘要:圆桌问题 思路:其实这道题用vector容器会大大方便很多,但是还是选择了使用while循环,走while循环的话,只需要注意圆桌就行了 代码: #include<iostream> #include<cstring> using namespace std; int main(){ int a[1 阅读全文
posted @ 2020-02-23 15:00 PCDL&TIPO 阅读(197) 评论(0) 推荐(0)
摘要:改革春风吹满地 思路:一个求多边形面积的题,关键在于多边形面积的求法 这个公式后面还要加xn*y1-yn*x1;证明网址贴上http://blog.csdn.net/sun_shine_/article/details/18799739 原文链接:https://blog.csdn.net/as3a 阅读全文
posted @ 2020-02-15 21:10 PCDL&TIPO 阅读(101) 评论(0) 推荐(0)
摘要:杨辉三角 思路:典型的杨辉三角问题,利用规律,可以计算每个位置的数值 代码: #include<iostream> using namespace std; int main(){ int n; int i, j, num; while (cin >> n) { for (i = 1; i <= n 阅读全文
posted @ 2020-02-15 20:57 PCDL&TIPO 阅读(124) 评论(0) 推荐(0)
摘要:汉字统计 思路:汉字机内码使用二个字节,汉字的每个字节都是<0的,即其每个字节最高位一位为1。C/C++语言补码第一位是符号位,1表示为负数,这就是这道题关键所在。 代码: #include<iostream> using namespace std; int main() { int n, sum 阅读全文
posted @ 2020-02-15 20:41 PCDL&TIPO 阅读(172) 评论(0) 推荐(0)
摘要:N皇后问题 这是第一次写DFS的问题,原来是会一点,但是现在忘得有点干净,重新看了看这八皇后的问题,当然,重新理解的时候依然遇到一些问题,参考了他人的博客@https://www.cnblogs.com/chenchengxun/p/3759278.html。 题目: 思路:这道题就是一个常见的DF 阅读全文
posted @ 2020-02-15 20:20 PCDL&TIPO 阅读(101) 评论(0) 推荐(0)
摘要:memset()函数 memset 函数是内存赋值函数,用来给某一块内存空间进行赋值的;包含在<cstring>头文件中,可以用它对一片内存空间逐字节进行初始化。 #include<iostream> #include<cstring> using namespace std; int main() 阅读全文
posted @ 2020-02-15 16:25 PCDL&TIPO 阅读(226) 评论(0) 推荐(0)
摘要:C++中Sort使用 头文件是#include <algorithm>; sort的使用 #include<iostream> #include<algorithm> using namespace std; bool cmp(int x, int y){ return x > y; } int m 阅读全文
posted @ 2020-02-15 15:48 PCDL&TIPO 阅读(161) 评论(0) 推荐(0)
摘要:sort 思路:正常使用sort即可,注意是从大到小排序,需要一个cmp函数保证排序,如果使用cin和cout会超时,所以,改用时间短的scanf和printf。 代码: #include<iostream> #include<algorithm> using namespace std; int 阅读全文
posted @ 2020-02-15 13:54 PCDL&TIPO 阅读(120) 评论(0) 推荐(0)
摘要:字符串统计 题目分析: 录入字符串,判断数字有多少个,累加保存。 代码: #include<iostream> using namespace std; int main() { char a[100001]; int n; while (cin >> n&&n) { while (n--) { g 阅读全文
posted @ 2020-02-08 01:59 PCDL&TIPO 阅读(141) 评论(0) 推荐(0)
摘要:数据的交换输出 题目分析: 找到最小值,然后与第一个换位置 代码: #include<iostream> using namespace std; int main() { int n; int a[101]; while (cin >> n&&n) { int i,t, min = 99999; 阅读全文
posted @ 2020-02-08 01:56 PCDL&TIPO 阅读(170) 评论(0) 推荐(0)
摘要:青年歌手大奖赛_评委会打分 题目分析: 判断出最大值和最小值,然后删去,最后将留下的数进行平均 代码: #include <iostream> using namespace std; int main() { int n; while (cin>>n) { int score, sum = 0, 阅读全文
posted @ 2020-02-08 01:50 PCDL&TIPO 阅读(151) 评论(0) 推荐(0)
摘要:蟠桃记 题目分析: 很普通的一道函数题,利用所给的条件,进行过程的模拟,构造出一个函数 代码: #include<iostream> using namespace std; int fun(int m) { int sum = 0; if (m == 1) { return 1; } else{ 阅读全文
posted @ 2020-02-08 01:46 PCDL&TIPO 阅读(127) 评论(0) 推荐(0)
摘要:素数判定 题目分析: 构造一个判断素数的函数fun,利用fun函数判断区间内的素数。 代码: #include <iostream> #include <math.h> #define fun(n) n*n + n + 41 using namespace std; int prime(int n) 阅读全文
posted @ 2020-02-08 01:42 PCDL&TIPO 阅读(205) 评论(0) 推荐(0)
摘要:多项式求和 题目分析: 一道经典的入门算法题,利用for循环以及-1的累乘,进行计算,代码如下 代码: #include<iostream> using namespace std; int main(){ int i, n; int t = 1; int cnt; double sum, num; 阅读全文
posted @ 2020-02-08 01:39 PCDL&TIPO 阅读(181) 评论(0) 推荐(0)
摘要:水仙花数 题目分析: 水仙花数也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 3 位数,它的每个位上的数字的 3次幂之和等于它本身(例如:1^3 + 5^ 阅读全文
posted @ 2020-02-08 01:36 PCDL&TIPO 阅读(149) 评论(0) 推荐(0)
摘要:求数列的和 思路:利用sqrt函数计算根号,再依次累计相加 代码: #include<iostream> #include<math.h> using namespace std; int main() { double m, n; double num, sum; while (cin >> m 阅读全文
posted @ 2020-02-01 22:29 PCDL&TIPO 阅读(114) 评论(0) 推荐(0)
摘要:数值统计 思路:分为正数,负数,0,三类,然后分别统计 代码: #include<iostream> using namespace std; int main() { int n; double num; int a, b, c; while (cin >> n&&n) { a = b = c = 阅读全文
posted @ 2020-02-01 21:58 PCDL&TIPO 阅读(133) 评论(0) 推荐(0)
摘要:平方和与立方和 思路:判断奇数偶数,分别计算 代码: #include<iostream> using namespace std; int main() { int m, n; int num1, num2; while (cin >> m >> n) { int t, i; num1 = num 阅读全文
posted @ 2020-02-01 21:56 PCDL&TIPO 阅读(130) 评论(0) 推荐(0)
摘要:求奇数的乘积 思路:输入数据,判断奇数偶数,然后计算奇数乘积。 代码: #include<iostream> using namespace std; int main() { int n; int num, sum; while (cin >> n) { sum = 1; for (int i = 阅读全文
posted @ 2020-02-01 21:52 PCDL&TIPO 阅读(147) 评论(0) 推荐(0)
摘要:第几天? 思路:构建一个闰年和非闰年的二维数组模型:int a[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 阅读全文
posted @ 2020-02-01 21:37 PCDL&TIPO 阅读(110) 评论(0) 推荐(0)
摘要:成绩转换 思路:提前设好数组char a[] = "EEEEEEDCBAA";计算成绩%10,看看是什么成绩 代码: #include<iostream> using namespace std; int main() { char a[] = "EEEEEEDCBAA"; int num; whi 阅读全文
posted @ 2020-02-01 21:30 PCDL&TIPO 阅读(195) 评论(0) 推荐(0)
摘要:求绝对值 思路:利用fabs函数计算绝对值,最后输出。 代码: #include<iostream> #include<math.h> using namespace std; int main() { double num; while (cin>>num) { printf("%0.2lf\n" 阅读全文
posted @ 2020-02-01 21:25 PCDL&TIPO 阅读(123) 评论(0) 推荐(0)
摘要:计算球体积 思路:输入数据,利用公式计算体积。 注:PI的值以及小数位数 代码: #include<iostream> #define PI 3.1415927 using namespace std; int main() { double r; while (cin >> r) { printf 阅读全文
posted @ 2020-02-01 21:21 PCDL&TIPO 阅读(123) 评论(0) 推荐(0)
摘要:ASCII码排序 思路:利用ascll表比较大小 代码: #include<iostream> using namespace std; int main() { char a, b, c, t; while (cin >> a >> b >> c) { if (a > c) { t = a; a 阅读全文
posted @ 2020-02-01 21:15 PCDL&TIPO 阅读(123) 评论(0) 推荐(0)
摘要:计算两点间的距离 思路:录入数据后,利用两点间公式计算答案 代码: #include<iostream> #include<math.h> using namespace std; int main() { double x1, y1, x2, y2; while (cin >> x1 >> y1 阅读全文
posted @ 2020-02-01 21:03 PCDL&TIPO 阅读(133) 评论(0) 推荐(0)
摘要:An easy problem 规律:当a >= 'a'&&a <= 'z' 时,sum = -(a - 'a') - 1; 当a >= 'A'&&a <= 'Z'时,sum = a - 'A' + 1; 代码: #include<iostream> using namespace std; int 阅读全文
posted @ 2020-02-01 20:59 PCDL&TIPO 阅读(92) 评论(0) 推荐(0)