题解
遇见生活222
此号不用
展开
-
7-1 银行业务队列简单模拟 (25分)
// 7-1#include <iostream>#include <algorithm>#include <queue>#include <vector>using namespace std;int n;queue<int>qa;queue<int>qb;vector<int>v;int main(){ cin >> n; int x; for(int i =.原创 2020-11-03 18:53:13 · 714 阅读 · 0 评论 -
7-1 学生顺序表的建立 (10分)
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int N = 10;struct edge{ int id; string name; double a,b,c;}p[N];int main(){ int n; cin >> n; .原创 2020-11-03 18:52:07 · 1525 阅读 · 0 评论 -
7-2 求素数个数 (30分)
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int N = 1e7 + 10;int primes[N], cnt; // primes[]存储所有素数int euler[N]; // 存储每个数的欧拉函数bool st[N]; // st[x.原创 2020-11-03 18:50:54 · 3415 阅读 · 1 评论 -
7-1 求最小值和次小值 (25分)
// 我就是为了来收割一波阅读量的#include <iostream>#include <algorithm>#include <set>using namespace std;// set 的简单用法,这个C++,肯定学了const int N = 1e6 + 10;int a[N];set<int>st;int n;int main(){ ios::sync_with_stdio(false); cin >.原创 2020-11-03 18:49:14 · 661 阅读 · 0 评论 -
PAT 1058 选择题
#include <iostream>#include <algorithm>#include <vector>#include <string>using namespace std;const int N = 110;int b[N];struct A{ int score; // 本题的分数 int se...原创 2019-11-19 20:28:42 · 78 阅读 · 0 评论 -
6-1 顺序表操作集 (20 分)-数据结构第2章
List MakeEmpty(){ List head =malloc(MAXSIZE*sizeof(struct LNode)); head->Last = 0; return head;}Position Find( List L, ElementType X ){ int i = 0; for(i = 0;i < L-...原创 2019-10-07 19:51:39 · 1363 阅读 · 0 评论 -
7-1 重排链表 (25 分)-数据结构第2章
/* 代码非原创*/#include<iostream>#include<vector>#include<cstdio>using namespace std;struct LNode{ int add; int data; int next;}List[100000];int main(){ int fa, n; vec...原创 2019-10-07 19:50:54 · 1395 阅读 · 0 评论 -
7-3 约瑟夫环 (25 分)-数据结构第2章
#include <iostream>using namespace std;#include <vector>struct Node{ int data; Node*next;};int main(){ int n, m; cin >> n >> m; vector<int>res; Node * firs...原创 2019-10-07 19:49:38 · 1723 阅读 · 0 评论 -
7-5 输出10个不重复的英文字母
做完这个题先说一下做完这个题的总结1.掌握使用set来判重 下面是set的一些操作方法2.会使用list 下面是list的一些操作方法list的就先补补充了,以后再补充3.下面是这个题目的AC代码str = input("")st = set(" ")ls = []for i in str: if i not in st: ...原创 2019-09-26 22:49:21 · 1658 阅读 · 0 评论 -
7-3 jmu-python-分段函数&数学函数
经过努力,哇,这个题终于过了;我先说一下做完这个题的一些总结吧首先 使用了 eval 这个函数,还有 import mathabs(x) 返回x的绝对值math.sqrt(x) 返回x的平方根如果想进位的我们可以先乘以10000,然后取余判断,然后再处以10000print("{:.3f}".format(x))这个会打印x的小数点后三位(这个会进行进位的,如果小数点第4位...原创 2019-09-26 21:19:20 · 5182 阅读 · 0 评论 -
6-2 顺序表的有序插入操作 (10 分)-数据结构第2章
int SqInsert(SqList &L,ElemType e){ for(int j = 0;j<L.length-1;j++) { if(L.elem[j]>L.elem[j+1])return 0; } int i; for(i = 0;i<L.length;i++) { if(L.elem[i]>e)break; ...原创 2019-10-07 19:52:16 · 2002 阅读 · 0 评论 -
6-3 尾插法创建单链表(C) (25 分)-数据结构第2章
struct Node* buildLinkedList(int* arr, int n){ struct Node* head = malloc(n*sizeof(struct Node)); struct Node* p = head; int i; for(i = 0;i < n;i++) { struct Node* p...原创 2019-10-07 19:52:53 · 919 阅读 · 0 评论 -
6-4 带头结点的单链表插入操作 (10 分)-数据结构第2章
int insert_link ( LinkList L,int i,ElemType e){ if(i<=0)return 0; LinkList p = L; LinkList pre = p; int count = 1; if(!L)return 0; while(p) { pre = p; ...原创 2019-10-07 19:53:28 · 3491 阅读 · 0 评论 -
程序填空题-数据结构第2章
原创 2019-10-08 21:25:32 · 431 阅读 · 0 评论 -
6-11 判断链表结点对称 (10 分)-数据结构第2章
void DispList(DLinkNode* L){ DLinkNode* p = L->next; int i = 0; while (p) { printf("%c ", p->data); if (p == L->prior)break; p = p->next; } printf("\n");}int Symm(D...原创 2019-10-08 21:24:04 · 597 阅读 · 0 评论 -
6-10 Add Two Polynomials (20 分)-数据结构第2章
/* Your function will be put here */Polynomial Add( Polynomial a, Polynomial b ){ if(!a->Next)return b; if(!b->Next)return a; Polynomial head = malloc(sizeof(Polynomial)); Polynomial p...原创 2019-10-08 21:23:34 · 385 阅读 · 0 评论 -
6-9 删除排序链表中的重复元素 (13 分)-数据结构第2章
/*删除排序链表中的重复元素*/LinkNode* deleteDuplicates(LinkNode* L){ LinkNode* p = L; while (p) { int d = p->data; LinkNode* p1 = p->next; LinkNode* pre = p; while (p1) { if (p1->...原创 2019-10-08 21:22:57 · 817 阅读 · 0 评论 -
6-8 单链表逆转 (20 分)-数据结构第2章
List Reverse( List L ){ if(!L)return NULL; List pc = L->Next; List pn = pc; List pre = L; while(pc) { pn = pc->Next; pc->Next = pre; pre = pc; pc = pn; } L->Nex...原创 2019-10-08 21:22:24 · 141 阅读 · 0 评论 -
6-7 链式表的按序号查找 (10 分)-数据结构第2章
ElementType FindKth(List L, int K){ int cnt = 0; List p = L; while (p) { cnt++; if (cnt == K) return p->Data; p = p->Next; } return ERROR;}原创 2019-10-07 19:55:24 · 281 阅读 · 0 评论 -
6-6 求链式表的表长 (10 分)-数据结构第2章
int Length(List L){ int cnt = 0; List p = L; while (p) { p = p->Next; cnt++; } return cnt;}原创 2019-10-07 19:54:45 · 129 阅读 · 0 评论 -
6-5 头插法创建单链表(C) (25 分)-数据结构第2章
struct Node* buildLinkedList(int* arr, int n){ struct Node* head = malloc(n * sizeof(struct Node)); struct Node* p = head; int i; for (i = n-1; i >= 0; i--) { struct Node* pc= malloc(...原创 2019-10-07 19:54:06 · 1132 阅读 · 0 评论 -
链表逆转6-8
List Reverse( List L ){ if(!L)return NULL; List pc = L->Next; List pn = pc; List pre = L; while(pc) { pn = pc->Next; pc->Next = pre; pre = pc; pc = pn; } L->Nex...原创 2019-09-25 09:14:52 · 113 阅读 · 1 评论 -
7-3 约瑟夫环 (25 分)
很明显这是一个循环链表,当报到这个同学的时候我们把这个同学删除就好了;本蒟蒻的代码有些简陋,还没有及时修改,请见谅#include <iostream>using namespace std;#include <vector>struct Node{ int data; Node*next;};int main(){ int n, m; cin...原创 2019-09-23 11:41:54 · 1690 阅读 · 0 评论 -
7-2 链表去重 (25 分) - 数据结构第2章
这个题目我自己开始就是用最传统的方法来做这个题,也就是和选择排序差不多的思路;只不过是不是交换而是删除;也就是先记录下链表当中第一个数字;然后拿这个数字和剩余的数字进行比较,如果相同则把当前这个节点删除,也就是将前一个节点指向该节点的下一个节点(和动态链表中的删除操作一样),然后就把这个删除的节点存到一个容器当中(这里我用的queue),然后接着用链表中的第二个数字,和剩余的数字进行比较,重复...原创 2019-09-23 11:39:47 · 2553 阅读 · 0 评论 -
7-3 复数相加
/*题目大体意思:题目:一个复数类,运算符重载 + ,实现复数和复数的相加。输入一组复数,每行一个复数,直到输入0结束。 输出这组复数的结果。提示: 复数的输入和输出符合数学书写规范输入示例3+2i2+3i0输出示例5+5i*/这个题有很多坑,其中一个让我陷入最深的坑为这个题是多个复数相加,弄的我以为是两个复数相加,这个坑让我惨败,浪费了我大量的时间,所以...原创 2019-04-22 20:44:37 · 2202 阅读 · 0 评论 -
牛客网小A的回文串
//QQ:54573339来源:牛客网题目描述小A非常喜欢回文串,当然我们都知道回文串这种情况是非常特殊的。所以小A只想知道给定的一个字符串的最大回文子串是多少,但是小A对这个结果并不是非常满意。现在小A可以对这个字符串做一些改动,他可以把这个字符串最前面的某一段连续的字符(不改变顺序)移动到原先字符串的末尾。那么请问小A通过这样的操作之后(也可以选择不移动)能够得到最大回文子串的...原创 2019-04-14 21:41:19 · 222 阅读 · 0 评论 -
递归实现组合型枚举
QQ:54573339题目:从 1~n 这 n 个整数中随机选出 m 个,输出所有可能的选择方案。输入格式两个整数 n,m,在同一行用空格隔开。输出格式按照从小到大的顺序输出所有方案,每行1个。首先,同一行内的数升序排列,相邻两个数用一个空格隔开。其次,对于两个不同的行,对应下标的数一一比较,字典序较小的排在前面(例如1 3 5 7排在1 3 6 8前面)...原创 2019-04-12 19:04:52 · 133 阅读 · 0 评论 -
递归实现指数型枚举
题目:从 1~n 这 n 个整数中随机选取任意多个,输出所有可能的选择方案。输入格式输入一个整数n。输出格式每行输出一种方案。同一行内的数必须升序排列,相邻两个数用恰好1个空格隔开。对于没有选任何数的方案,输出空行。本题有自定义校验器(SPJ),各行(不同方案)之间的顺序任意。1≤n≤15输入样例:3输出样例322 311 31 21 2...翻译 2019-04-12 18:46:07 · 94 阅读 · 0 评论 -
Minimum Depth of Binary Tree
//QQ:54573339;此代码是盗用yxc大神的代码;我自己不会写这种递归性的代码;本题就是给你一棵二叉树,让你求其最小的深度/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *...原创 2019-04-15 20:00:23 · 66 阅读 · 0 评论 -
PAT乙级1015德才论
首先呢这个题目我相信大家都已经了解了;关键是做题的过程中可能会超时;我用了两种方法;这两种方法是一样的思路;只是输入输出的形式不一样;我就是把这四种人放在4个不同的容器里;然后用快排分别对他们进行排序;如果使用其他的冒泡或者选择排序的话这样做也会超时的;如果使用C++的话,不关闭输入输出流,这个也会超时的;但是使用C语言的scanf和printf,这样就不会超时了;这个题思路很明确:也...原创 2019-04-01 11:36:11 · 187 阅读 · 0 评论 -
最长对称字串长度
/*最长对称字串长度*/#include<iostream>using namespace std;#include <string>#include <list>#include <cmath>#include <vector>#include <algorithm>#include <set&...原创 2019-03-19 13:00:18 · 138 阅读 · 0 评论 -
出租车
/* 题目链接: http://codeup.cn/problem.php?cid=100000584&pid=1 */ /* 这个题自己算一下就行,因为要求求最小的钱; 看懂地三个样例,这个题就能做出来了; */ #include<bits/stdc++.h> using namespace std; #define ll long long int...原创 2019-03-18 22:53:25 · 515 阅读 · 0 评论 -
出租车费
/* 题目链接: http://codeup.cn/problem.php?cid=100000584&pid=1 */ /* 这个题自己算一下就行,因为要求求最小的钱; 看懂地三个样例,这个题就能做出来了; */ #include<bits/stdc++.h> using namespace std; #define ll long long int m...原创 2019-03-18 22:44:54 · 240 阅读 · 0 评论 -
看电视
/* http://codeup.cn/problem.php?cid=100000584&pid=0*/#include <iostream> using namespace std;#include <algorithm>struct Televison{ int si,ei;};bool com(Televison t1,Televison...原创 2019-03-18 21:53:58 · 98 阅读 · 0 评论 -
总结报告
代码:/*此代码我是抄袭的*/#include <iostream>using namespace std;const int N =5010;int g[N][N];int main(){ int n,r,x,y,w; cin>>n>>r; int mx=r,my=r; for(int i=1;i<...翻译 2019-04-28 19:43:34 · 99 阅读 · 0 评论 -
B. Neko Performs Cat Furrier Transform
#include <iostream> using namespace std;#include <vector>#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); vector<int>res;//这里是装数字,也就是A步骤操作的时候,操作的位数 int ...原创 2019-04-28 20:40:41 · 148 阅读 · 0 评论 -
7-1 数据的最大值问题(重载+函数模板)
其实这个题和以前的那个复数相加是差不多的,主要是练习字符串流(这个题其实是练习模板,因为我模板并不是很会,所以过些时间再补充一下模板是怎么做的吧)#include <iostream> #include <cmath>#include <sstream>#include <string>using namespace std;int...原创 2019-05-04 19:34:43 · 2850 阅读 · 0 评论 -
AtCoder - 2394
这个题呢,如果用暴力的话,首先数组是存不下的,其次,这样一定会超时的;因为你要算(n-1)+(n-2)+.....超级多次;所以呢我们必须通过另一种方法来达到我们的目的;这个题:我们是要求面积;我们首先来看第一个样例:这个60 是怎么出来的是s= (x2-x1)*(y2-y1)+(x3-x1)+(y2-y1)+(y3-y2)*(y2-y1)+(x2-x1)*(y3-y1)....原创 2019-08-02 08:06:49 · 130 阅读 · 0 评论 -
F - Stones in the Bucket ZOJ - 4118
这个题直接找比平均数大的石子的个数就行了,因为我们最终的目的,就是让他们一样!!;#include <iostream> #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #include <cstdio>#include <string.h>#incl...原创 2019-05-26 19:05:35 · 94 阅读 · 0 评论 -
M - Sekiro ZOJ - 4125
这个题按照题目的要求来做就OK了#include <iostream> #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #include <cstdio>using namespace std;typedef long long ll;int main(){...原创 2019-05-26 19:02:04 · 100 阅读 · 0 评论