西安交通大学《915》2015-2021编程题解析
xjt-se考研专业课真题解析
乐行僧丶
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
西安交通大学915-2015-编程4
题目描述:解题思路:设置计数器遍历链表代码实现:#include <iostream>#include <algorithm>using namespace std;struct Lnode { int data; Lnode* next; Lnode() {} Lnode(int data, Lnode* next) : data(data), next(next) {}};int caortx(Lnode* HL,原创 2021-12-16 07:52:40 · 1574 阅读 · 0 评论 -
西安交通大学915-2015-编程3
题目描述:解题思路:候选人类,设置计数器设置候选人数组代码实现:#include <iostream>#include <algorithm>using namespace std;struct Candidate { string name; int cnt;};const int N = 100;Candidate arr[N];int main() { int n, m; cout << "ple原创 2021-12-16 07:46:17 · 880 阅读 · 0 评论 -
西安交通大学915-2015-编程2
题目描述:解题思路:使用map统计遍历一次字符串代码实现:#include <string>#include <map>#include <iostream>using namespace std;void Count(const string& s) { map<char, int> mp; for (auto c : s) { mp[c]++; } for (auto k:原创 2021-12-14 22:38:45 · 966 阅读 · 0 评论 -
西安交通大学915-2015-编程1
题目描述:解题思路:矩阵为n阶主对角线 mat[i][i]副对角线 i + j == n - 1代码实现:#include <iostream>using namespace std;const int N = 3;void sum(int mat[N][N], int row, int col) { int dg = 0; int udg = 0; for (int i = 0; i < row; i++) {原创 2021-12-13 11:02:04 · 994 阅读 · 0 评论 -
西安交通大学915-2016-编程3
题目描述:代码实现:#include <iostream>using namespace std;enum STATUS { NORMAL = 0, // 正常 LATE = 1, // 迟到 LEAVE = 2, // 请假 ABSENT = 3 // 旷课};struct Student { int id; int course[4]; int sum;};const int N = 110;S原创 2021-12-12 14:06:05 · 308 阅读 · 0 评论 -
西安交通大学915-2016-编程2
题目描述:解题思路:数字转化为字符串 itoa用字符串处理代码实现:#include <iostream>#include <cstring>#include <cstdlib>using namespace std;#define N 128int Count(int m, int n) { char num[N] = {0}; itoa(m, num, 10); int cnt = 0; int i = 0原创 2021-12-12 13:26:36 · 275 阅读 · 0 评论 -
西安交通大学915-2016-编程1
题目描述:解题思路:遍历一次序列 时间复杂度O(n)代码实现:#include <iostream>#include <cstring>using namespace std;void RemoveDigitInStr(char *s) { int n = strlen(s); int i = 0; int j = 0; while (s[j] != '\0') { if (!isdigit(s[j])) {原创 2021-12-12 13:18:06 · 417 阅读 · 0 评论 -
西安交通大学915-2017-编程4
题目描述:解题思路:如果m >= n,机器的数量更多,每台机器给分配一个作业即可,不用设计等待时间如果m < n,作业的数量更多,优先选择长时间任务执行,短任务等待时间少代码实现:#include <iostream>#include <algorithm>#include <cstdio>using namespace std;const int N = 100;int target[N]; // 存储完成任务所需要的时间int m原创 2021-12-11 20:19:22 · 215 阅读 · 0 评论 -
西安交通大学915-2017-编程3
题目描述:设有两个栈s1, s2都采用顺序存储方式,并且共享一个存储区域[0, … , maxsize - 1],为了尽量使用空间,减少溢出的可能,可采用栈顶相向,迎面增长的存储方式,请设计s1, s2的出栈,进栈操作算法。要求:采用空间策略;算法数据结构;写出算法步骤解题思路:分为左栈和右栈,左栈栈顶指针初始为-1,右栈栈顶指针初始为maxsize共享栈满的条件:top1 + 1 == top2左栈空的条件:top1 == -1右栈空的条件:top2 == maxsize代码实现:#原创 2021-12-11 19:30:52 · 743 阅读 · 0 评论 -
西安交通大学915-2017-编程1
题目描述:解题思路:[1, 2, 3, 4, 5, 6] n = 6 k = 1倒数第一个,是正数的第六个倒数第k个,是正数的第n - k + 1个代码实现:#include <iostream>using namespace std;struct ListNode { ListNode* next; int data;};bool FindReverseKthInLinkedList(ListNode* head, int k) { aut原创 2021-12-11 18:57:51 · 252 阅读 · 0 评论 -
西安交通大学915-2017-编程2
题目描述:解题思路:二分查找模板注意边界 l <= r注意整型加法溢出,改用减法代码实现:package mainimport "fmt"func BinSearch(a []int, x int) int { l := 0 r := len(a) - 1 for l <= r { m := (r-l)/2 + l if a[m] == x { return m } else if a[m] < x { l = m + 1 } e原创 2021-12-11 18:47:25 · 275 阅读 · 0 评论 -
西安交通大学915-2018-编程2
题目描述:解题思路:选择一种稳定的排序算法,针对成绩关键字进行排序抽象学生类代码实现:#include <iostream>#include <map>#include <string>#include <algorithm>using namespace std;struct Student { std::string name; int score;};namespace lsc { void sw原创 2021-12-11 09:26:18 · 244 阅读 · 0 评论 -
西安交通大学915-2018-编程4
题目描述:解题思路:球盒模型dp,状态表示,f[n][m]表示在n个箱子里放入m个小球放置方法的数量状态计算,m < n, 即球数小于箱子数,f[n][m] = f[n][n]m >= n, 即球数大于箱子数,分为两种箱子满,箱子不满 f[n][m] = f[n-m][m] + f[n-1][m]箱子满 f[n-m][m]至少有一个箱子不满f[n-1][m]代码实现:#include <iostream>using namespace std;i原创 2021-12-11 09:12:37 · 199 阅读 · 0 评论 -
西安交通大学915-2018-编程3
题目描述:解题思路:判断闰年和平年计数代码实现:#include <iostream>using namespace std;bool IsLeapYear(int x) { return ((x % 400 == 0) || (x % 4 == 0 && x % 100 != 0));}int month[2][13] = { {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},原创 2021-12-11 08:36:31 · 227 阅读 · 0 评论 -
西安交通大学915-2018-编程1
题目描述:解题思路:遍历序列,使用map存储代码实现:#include <iostream>#include <map>#include <string>using namespace std;void RemoveSpace(string &s) { string ans = ""; for (auto & c : s) { if (c != ' ') { ans += c;原创 2021-12-11 01:03:19 · 177 阅读 · 0 评论 -
西安交通大学915-2019-编程3
题目描述:解题思路:暴力枚举,时间复杂度O(n^2)归并排序,merge函数的拓展,一次处理一个区间的逆序对数量,时间复杂度O(nlogn)代码实现:暴力枚举#include <iostream>#include <vector>using namespace std;int main() { vector<int> arr = {1, 3, 2, 5, 4, 7, 6}; int n = arr.size(); in原创 2021-12-11 00:06:26 · 561 阅读 · 0 评论 -
西安交通大学915-2019-编程2
题目描述:解题思路:包含空格,首先去除空格利用回文的定义,遍历一次代码实现:#include <iostream>#include <stack>#include <vector>#include <string>#include <map>#include <unordered_map>using namespace std;bool RecursionSolution(const string &a原创 2021-12-10 23:45:38 · 486 阅读 · 0 评论 -
西安交通大学915-2019-编程1
题目描述:解题思路:存储 + 遍历更新代码实现:#include <iostream>using namespace std;struct Pair { int x; int y;};const int N = 100;Pair arr[N];int idx = 0;namespace lsc { void min(Pair& mi, Pair& x) { if (x.x < mi.x || x.y &l原创 2021-12-10 23:12:12 · 330 阅读 · 0 评论 -
西安交通大学915-2020-编程3
题目描述:代码实现:// 直接爆搜#include <iostream>#include <vector>using namespace std;int cnt = 0;void dfs(int target, vector<int>& value, int u) { if (!target) { cnt++; return; } for (int i = u; i < value.s原创 2021-12-02 23:24:45 · 271 阅读 · 0 评论 -
西安交通大学915-2020-编程2
题目描述:代码实现:#include <stdio.h>#include <stdlib.h>#include <string.h>void swap(char*s, int i, int j) { char c = s[i]; s[i] = s[j]; s[j] = c;}void reverse(char* s, int i, int j) { while (i < j) { swap(s, i原创 2021-12-02 23:10:13 · 340 阅读 · 0 评论 -
西安交通大学915-2020-编程1
题目描述:代码实现:#include <iostream>using namespace std;int main() { for (int i = 0; i <= 9999; i++) { int a = i / 1000; int b = i % 1000 / 100; int c = i % 100 / 10; int d = i % 10; int t = c * 1000 +原创 2021-12-02 22:54:53 · 261 阅读 · 0 评论 -
西安交通大学915-2021-编程3
题目描述:代码实现:#include <iostream>#include <cstring>using namespace std;const int N = 110;int f[N]; // 状态表示 : f[i]表示第i天机器人的总数// 状态计算 : 第i天的机器人数量 = 第i-1天的机器人数量 + 第i-3天的机器人数量// 因为第i-3天的机器人数量到今天已经称为一个成熟的机器人,可以产生一个新的机器人// 状态转移方程 f[i] = f[i原创 2021-12-01 23:14:24 · 531 阅读 · 0 评论 -
西安交通大学915-2021-编程2
题目描述:代码实现:#include <iostream>#include <vector>#include <algorithm>using namespace std;// 获取一个数字的所有因子vector<int> GetDivisors(int x) { vector<int> ans; for (int i = 1; i < x; i++) { if (x % i == 0) {原创 2021-12-01 23:05:29 · 188 阅读 · 0 评论 -
西安交通大学915-2021-编程1
题目描述:代码:#include <iostream>#include <vector>using namespace std;int FindRowMinValue(vector<vector<int>> &g, int row) { int res = INT_MAX; for (int i = 0; i < g[row].size(); i++) { res = min(res, g[row]原创 2021-12-01 22:43:06 · 432 阅读 · 0 评论
分享