
C/C++
文章平均质量分 91
MNSmile
哈喽
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
set集合
头文件:#include详细用法(部分):set t ------ 定义一个int类型的容器,注意set里的每个元素只会出现1次t.insert(k) ------ 插入元素k,多次插入同一个元素后面无效t.count(k) ------ 判断元素k是否在容器内t.erase(k原创 2017-03-28 17:53:03 · 903 阅读 · 0 评论 -
1055 The World's Richest (25 分)
1055 The World’s Richest (25 分)题目意思:属性类型范围namestring长度 <= 8ageint(0-200]排序:net_worth非递增net_worth 相等age 非递减net_worth, age 都相等name 非递减开始代码 — 超时了/* 属性: ...原创 2018-11-07 17:18:00 · 417 阅读 · 0 评论 -
C++ 多次输入案例
while (scanf("%d%d",&n,&m)!=EOF) { ... }原创 2019-01-24 19:17:33 · 4006 阅读 · 1 评论 -
C++ 小结
1. 多次输入案例原创 2019-01-24 19:19:34 · 374 阅读 · 0 评论 -
C++ fill()和 memset()函数
转自 https://blog.youkuaiyun.com/liuchuo/article/details/52296646memset函数按照字节填充某字符在头文件<cstring>里面fill函数按照单元赋值,将一个区间的元素都赋同一个值在头文件<algorithm>里面因为memset函数按照字节填充,所以一般memset只能用来填充char型数组,(因为只有...转载 2019-01-24 19:27:58 · 676 阅读 · 0 评论 -
完美数列(25) C++版
题目分析 首先把数组按从大到小排序,更加方便。然后建两个循环,外循环表示最小值,内循环表示满足M<=N*p 的要求的数,每满足一次,cnp(代表构成一个完美数列的数量)数量就增加1。下次内循环就从( cnp+最小值 i )开始(表明此时已经知道一个满足完美数列数量是多少,唯一的问题就是确认cnp...原创 2019-01-23 17:57:40 · 932 阅读 · 0 评论 -
01-复杂度2 Maximum Subsequence Sum (25 分)
题目地址:PTA题目展示:Given a sequence of K integers { N1, N2, …, NK }. A continuous subsequence is defined to be { Ni, Ni+1, …, Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuou...原创 2019-03-24 21:52:46 · 3060 阅读 · 8 评论 -
C++ reverse函数
reverse 在 库中,用来翻转 [a,b) 之间的内容template <class BidirectionalIterator> void reverse (BidirectionalIterator first, BidirectionalIterator last){ while ((first!=last)&&(first!=--last)...原创 2019-03-29 20:15:12 · 4807 阅读 · 0 评论 -
B1001 1001 害死人不偿命的(3n+1)猜想 (15 分)
PAT卡拉兹(Callatz)猜想:对任何一个正整数 n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把 (3n+1) 砍掉一半。这样一直反复砍下去,最后一定在某一步得到 n=1。卡拉兹在 1950 年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证 (3n+1),以至于有人说这是一个阴谋,卡拉兹是在蓄意延...原创 2019-03-30 14:35:54 · 121 阅读 · 0 评论 -
B1001 1001 害死人不偿命的(3n+1)猜想 (15 分)
PAT卡拉兹(Callatz)猜想:对任何一个正整数 n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把 (3n+1) 砍掉一半。这样一直反复砍下去,最后一定在某一步得到 n=1。卡拉兹在 1950 年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证 (3n+1),以至于有人说这是一个阴谋,卡拉兹是在蓄意延...原创 2019-03-30 14:35:54 · 128 阅读 · 0 评论 -
B1011 A+B 和 C (15 分)
PAT1011 A+B 和 C (15 分)给定区间 [−231 ,231 ] 内的 3 个整数 A、B 和 C,请判断 A+B 是否大于 C。输入格式:输入第 1 行给出正整数 T (≤10),是测试用例的个数。随后给出 T 组测试用例,每组占一行,顺序给出 A、B 和 C。整数间以空格分隔。输出格式:对每组测试用例,在一行中输出 Case #X: true 如果...原创 2019-03-30 14:44:33 · 113 阅读 · 0 评论 -
B1016 部分A+B (15 分)
PAT1016 部分A+B (15 分)#include <iostream>#include <algorithm>using namespace std;int main() { //freopen("data.txt", "r", stdin); long long a, da, b, db; scanf("%lld %lld %l...原创 2019-03-30 14:48:52 · 137 阅读 · 0 评论 -
B1026 程序运行时间 (15 分)
PAT1026 程序运行时间 (15 分)要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数 CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 f 的运行时间,我们只要在调用 f ...翻译 2019-03-30 14:52:22 · 158 阅读 · 0 评论 -
B1046 划拳 (15 分)
PATB1046 划拳 (15 分)划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。输入格式:输入第一行先给出一个正整数 N(≤100),随...原创 2019-03-30 15:01:10 · 189 阅读 · 0 评论 -
B1008 数组元素循环右移问题 (20 分)
PATB1008 数组元素循环右移问题 (20 分)一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?输入格式:每个输入包含一个测试用例,第1行输入N(1≤N≤100)和M(≥0);第2行输入N个整数,之间用空格分隔。输出格式:在一行中输出循环右移M位以后的整数序列,之...原创 2019-03-30 15:19:13 · 203 阅读 · 0 评论 -
1046 Shortest Distance (20 分)
PAT原题The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed to tell the shortest distance between any pair of exits.Input Specification:Each input file ...原创 2019-06-12 23:06:17 · 226 阅读 · 0 评论 -
1028 List Sorting (25 分)
1028 List Sorting (25 分)传送门声明为全局数组,不然会报错。/* N<=10^5 C C=1 ID递增 C=2 name非递减 C=3 grade非递减 同样的名字或成绩,排序根据递增的ID */#include <bits/stdc++.h>using namespace std;struct node { int id; s...原创 2018-11-07 13:07:25 · 169 阅读 · 0 评论 -
1025 PAT Ranking (25 分)
1025 PAT Ranking (25 分)传送门#include <bits/stdc++.h> using namespace std;struct node { string id; int grade; int local_rank; int final_rank; int local_number;};bool cmp(node a, node b){...原创 2018-11-07 13:03:49 · 236 阅读 · 1 评论 -
1062 Talent and Virtue (25 分)
1062 Talent and Virtue (25 分)传送门#include <bits/stdc++.h>using namespace std;int n, lower, higher;struct people{ string name; int virtue; int talent;};bool cmp(people a, people b) { i...原创 2018-11-07 13:00:45 · 151 阅读 · 0 评论 -
数组实现线性表--王晓东《数据结构与算法设计》
arrList.h 自己的笔记,不喜勿喷,欢迎大佬指导#include &lt;malloc.h&gt;#define Error(module) fprintf(stderr,"error:"#module"\n")typedef struct alist *List;typedef struct alist{ int n; int maxsize; ...原创 2018-05-23 20:45:16 · 737 阅读 · 0 评论 -
C指针实现单链表---王晓东《数据结构与算法设计》
linkList.h 个人笔记,不喜勿喷,欢迎大佬指导#include <malloc.h>#define Error(module) fprintf(stderr,"error:"#module"\n")typedef struct node *link;typedef struct node { ListItem element; link...原创 2018-05-23 21:12:14 · 393 阅读 · 0 评论 -
数组实现栈----《数据结构与算法设计》
arrStack.h 个人笔记#include &lt;errno.h&gt;#include &lt;malloc.h&gt;typedef int StackItem;typedef struct astack *Stack;typedef struct astack { int top; int maxtop; StackItem *dat...原创 2018-05-23 21:22:01 · 213 阅读 · 0 评论 -
链表实现栈----《数据结构与算法设计》
linkStack.h 个人笔记#include &amp;lt;malloc.h&amp;gt;#define Error(module) fprintf(stderr,&quot;error:&quot;#module&quot;\n&quot;)typedef int StackItem;typedef struct stacknode *slink;typedef struc原创 2018-05-23 21:27:32 · 170 阅读 · 0 评论 -
链表实现队列----《数据结构与算法设计》
linkQueue.h 个人笔记#include <errno.h>#include <malloc.h>#include <stdio.h>#include <stdlib.h>#define Error(module) fprintf(stderr,"error:"#module"\n")//实现指针节点type...原创 2018-05-23 21:31:31 · 180 阅读 · 0 评论 -
pat 甲级题
to_string(a+b) 函数1001 A+B Format (20 分)原创 2018-10-18 14:11:07 · 249 阅读 · 0 评论 -
1003 Emergency (25 分)--- Dijkstra求解
题目地址: 1003 Emergency (25 分本题本质就是求起点到目标点最短路径#include &amp;lt;bits/stdc++.h&amp;gt; using namespace std;int n, m, c1, c2; //n为城市数,m为道路数,c1为起点,c2为目标点 int INF = 0x3fffffff;const int maxn = 1010;bool vis[ma...原创 2018-10-19 17:46:50 · 1094 阅读 · 2 评论 -
1042 Shuffling Machine (20 分)
题目地址:1042 Shuffling Machine (20 分)模拟题,定义一个新的字符串数组作为中间产物临时存放卡牌。每执行一次,中间数组更新一次,然后在复制到卡牌数组中。代码#include <bits/stdc++.h>using namespace std;string a[] = {"0","S1","S2","S3","S4","S5"原创 2018-10-22 21:42:14 · 408 阅读 · 0 评论 -
1065 A+B and C (64bit) (20 分)
1065 A+B and C (64bit) (20 分)代码c++版#include &lt;bits/stdc++.h&gt;using namespace std;int main() { long long a, b, c, sum; int n; cin&gt;&gt;n; for (int i = 0; i &lt; n; i++) { cin&gt;&gt;a&原创 2018-10-23 20:26:41 · 237 阅读 · 0 评论 -
1009 Product of Polynomials (25 分)
1009 Product of Polynomials (25 分)代码:#include <bits/stdc++.h>using namespace std;const int maxn=10000;int main() { //数组a,b用来接收指数和系数, //数组c用来接收a和b相乘的指数和系数 double a[maxn], b[maxn], c[maxn...原创 2018-10-23 22:01:10 · 214 阅读 · 0 评论 -
1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分)代码#include &lt;bits/stdc++.h&gt; using namespace std;int main() { int n, m; int maxn = 1010; double a[maxn]; memset(a,0,sizeof(double)*maxn); cin&gt;&gt;n; i...原创 2018-10-23 22:04:48 · 183 阅读 · 0 评论 -
1011 World Cup Betting (20 分)
1011 World Cup Betting (20 分)代码:#include <bits/stdc++.h>using namespace std;int main() { char s[5] = {'W','T','L'}; double a[5]; double ans = 1.0; for (int i = 0; i < 3; i++) { int...原创 2018-10-25 00:00:05 · 123 阅读 · 0 评论 -
1031 Hello World for U (20 分)
1031 Hello World for U (20 分)题目意思就是给你一串字符串,给出U型图。方法:求出字符串长度 n , 然后得 m = n+2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;然后再得到 n1=n3=m/3,同时n2 = m - n1*2;我写的代码原创 2018-10-30 15:47:25 · 191 阅读 · 0 评论 -
1019 General Palindromic Number (20 分)
1019 General Palindromic Number (20 分)#include <bits/stdc++.h> using namespace std;bool isPnum(int a[], int len) {//判断是否是回文数 bool flag = true; for (int i = 0; i < len/2; i++){ if (a[i]...原创 2018-10-30 19:18:52 · 117 阅读 · 0 评论 -
1005 Spell It Right (20 分)
1005 Spell It Right (20 分)数字相加,输出总和对应每个字的英文#include &lt;iostream&gt;using namespace std;string s1[10] = {"zero","one","two","three","four",&qu原创 2018-11-02 13:20:26 · 288 阅读 · 0 评论 -
1061 Dating (20 分)
1061 Dating (20 分)pat传送门#include <bits/stdc++.h> using namespace std;string s[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"}; int main(){ //freopen("datain.txt原创 2018-11-02 13:25:18 · 242 阅读 · 0 评论 -
1001 A+B Format (20 分)
PAT原题【注】转载自柳婼女神的 1001. A+B Format (20)-PAT甲级真题Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than f...转载 2019-06-12 23:20:42 · 2960 阅读 · 5 评论