![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
zmqgeek
这个作者很懒,什么都没留下…
展开
-
瓜大2017机试—字符串重组
题目:从键盘输入一个字符串(不多于80个字符),将其中的数字字符按原顺序组成一个新字符串,并输出。#include<iostream>#include<cstring>using namespace std;int main(){ char str[80],strs[80]; int j=0; gets(str); int len=strlen(st...原创 2019-02-21 15:13:50 · 164 阅读 · 0 评论 -
图论—DFS
#include<iostream>using namespace std;const int MAXV=1000;//最大顶点数 int n,m,G[MAXV][MAXV]={0};//邻接矩阵 bool vis[MAXV]={false};//标记数组 void DFS(int u,int depth){ vis[u]=true;//标记u已访问 cout&...原创 2019-03-09 17:22:20 · 271 阅读 · 0 评论 -
图论—Dijkstra
#include<iostream>using namespace std;const int MAXV=1000;//最大顶点数 const int INF=100000000;//设INF是一个很大的数 int n,m,s,G[MAXV][MAXV];int d[MAXV];//起点到各点的路径长度 bool vis[MAXV]={false}; //访问标记数组...原创 2019-03-09 16:44:36 · 286 阅读 · 0 评论 -
图论—拓扑序列
#include<iostream>#include<cstdio>#include<queue>#include<vector>using namespace std;const int maxv=1000; vector<int> G[maxv];//邻接表 int n,m,inDegree[maxv]={0};//...原创 2019-03-09 16:39:30 · 433 阅读 · 0 评论 -
字符串字符反转
#include<iostream>#include<cstring>using namespace std;int main(){ char str[20]; gets(str); int len=strlen(str),top=0; char st[len]; for(int i=0;i<len;i++) { st[top++]=...原创 2019-02-26 21:46:08 · 177 阅读 · 0 评论 -
C(n,m),排列组合
#include<iostream>using namespace std;long long C(long long n,long long m){ long long ans=1; for(int i=1;i<=m;i++) { ans=ans*(n-m+i)/i; } return ans;}int main(){ long long n,...原创 2019-02-26 21:28:32 · 1587 阅读 · 0 评论 -
瓜大2017机试—字符串倒序
题目:请编写程序,将用户输入的一个字符串(不多于100个字符),其中单词按照逆序,重新输出。例如输入字符串"this is a dog",输出为"dog a is this"。第一种方法:采用字符数组进行单词的倒序。#include<iostream>#include<cstring>using namespace std;int main(){ ch...原创 2019-02-20 21:20:28 · 258 阅读 · 0 评论 -
DP—最长不下降子序列
#include<iostream>#include<algorithm>using namespace std;const int N=100;int A[N],dp[N];int main(){ int n; cin>>n; for(int i=1;i<=n;i++) { cin>>A[i]; } int...原创 2019-02-20 09:33:06 · 661 阅读 · 0 评论 -
DP—最长连续子序列和
#include<iostream>#include<algorithm>using namespace std;const int maxn=10010;int main(){ int n,A[maxn],dp[maxn]; cin>>n; //元素个数 //读入序列 for(int i=0;i<n;i++) { cin&...原创 2019-02-20 09:04:48 · 304 阅读 · 0 评论 -
快排应用—求第k大的数
利用快速排序来查找无序数组中第K大的数,通过判断下标,只计算有k的那一半,时间复杂度为 O(n).#include<iostream>using namespace std;const int maxn=256;int Partition(int A[],int left,int right){ int temp=A[left]; while(left<rig...原创 2019-02-19 21:11:08 · 1402 阅读 · 0 评论 -
字符串处理—删除其中数字
题目:将输入的字符串中的数字删除,输出删除完成后的字符串#include<iostream>using namespace std;void Delete(char str[]){ int i=0,j=0; while(str[i]!='\0')//扫描字符 { //将字符中的数字跳过 while(str[i]>='0'&&str[...原创 2019-02-19 20:23:52 · 4259 阅读 · 2 评论 -
瓜大2018机试—字母大小写转换
题目:编程输入一个字符串,将所有大写英文字母改为小写英文字母,所有小写英文字母改为大写英文字母,然后输出。先定义字符串,并输入,然后对字符串进行遍历,并判断是否是大写字母,如果是则其ASCII加32,如果是小写字符则其ASCII减去32,最后输出字符串即可,代码如下:#include<iostream>using namespace std;int main(){ ...原创 2019-02-18 11:16:55 · 289 阅读 · 0 评论 -
瓜大2018机试—判断回文数
题目:有这样一类数字,顺着看和倒着看是相同的数,例如121,656,2332等,这样的数字就称为回文数字。编程判断某数字是否是回文数字。为了防止空间限制和溢出,因此采用数字位判断法。先比较整数的第1位和最后1位是否相等,如果不等,则直接返回false;若相等,则接下去判断剩下的位置,如同回文字符串判断的过程一样。代码如下:#include<iostream>using ...原创 2019-02-18 10:34:39 · 161 阅读 · 0 评论 -
图论—BFS
#include<iostream>#include<queue>#include<vector>using namespace std;const int MAXV=1000;//最大顶点数int n,m;//顶点数,边数 vector<int> G[MAXV];//邻接表 bool vis[MAXV]={false};//访问...原创 2019-03-09 17:46:01 · 348 阅读 · 0 评论