
算法笔记
Ston.V
2016年一个枯槁憔悴的春天,在华科毫无目的的浪费了一年半的时间后,我终于选定了嵌入式方向。其实这选择并不是突发奇想,当年有对智能家居,物联网感兴趣,但偶然进入软件这坑爹的专业,还好大二下开了计组,操原等课程,对底层产生兴趣,再加上计算机三级考试若干方向,又加之网课老师还不错就干脆跳坑。虽前路艰辛,愿初心不改。
2021夏天,回到华科读研,存储方向,仍然是嵌入式。是深坑但已经懒得爬出来了。
展开
-
写简单code犯的弱智问题1
1.提前终止输入检测一个矩阵是否是对称矩阵我的问题code#include<bits/stdc++.h>using namespace std;const int maxn=101;int buf[maxn][maxn];int main(){ int n; while(cin>>n){ bool flag=true; for(int i=0;i<n;i++){ for(int j原创 2021-03-07 22:29:20 · 128 阅读 · 0 评论 -
使用C++ STL(string) 中的一些小毛病1
1.sscanf和sprintf的原型要想起scanf(screen,"%d",&n);printf(screen,"%d",n);这样就是到是从右往左还是从左往右了//把字符数组str的内容以%d的格式写到n中,从左往右sscanf(str,"%d",&n);//将n以%d的格式写到字符数组中去,从右往左sprintf(str,"%d",n);//若str为string类型,可以转化为c的字符数组类型;strcpy(buffer,str.c_str());//s原创 2021-03-03 15:39:19 · 132 阅读 · 1 评论 -
[PAT A1060 Are They Equal]
[PAT A1060 Are They Equal]Description:f a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as0.123×105with simple chopping. Now given the number of significant digits on..原创 2021-02-03 00:12:44 · 100 阅读 · 0 评论 -
[算法笔记 大整数相加]
[算法笔记 大整数相加]Description:大整数相加,这里用string输入,转为int类型数组存数,数组低位存整数的低位(个位存在index=0的地方)CODE:#include <cstdio>#include <cstring>const int maxlen=10000;struct Bign{ int data[maxlen]; int len; Bign(){ len=0; mem.原创 2021-02-02 09:57:46 · 227 阅读 · 0 评论 -
[PAT A1059 Prime Factors]
[PAT A1059 Prime Factors]Description:Given any positive integerN, you are supposed to find all of its prime factors, and write them in the formatN=p1k1×p2k2×⋯×pmkm.Input Specification:Each input file contains one t...原创 2021-02-01 22:10:19 · 133 阅读 · 0 评论 -
[PAT B1013 数素数]
[PAT B1013 数素数]Description:令Pi表示第i个素数。现任给两个正整数M≤N≤104,请输出PM到PN的所有素数。输入格式:输入在一行中给出M和N,其间以空格分隔。输出格式:输出从PM到PN的所有素数,每 10 个数字占 1 行,其间以空格分隔,但行末不得有多余空格。输入样例:5 27输出样例:11 13 17 19 23 29 31 37 41 4347 53 59...原创 2021-02-01 20:34:07 · 192 阅读 · 0 评论 -
[codeup 1818最大公约数]
[codeup 1818最大公约数]题目:求最大公约数与最小公倍数CODE#include <cstdio>int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b);}int lcm(int gcd,int a,int b){ return (a/gcd)*b;}int main(){ int a,b; scanf("%d %d",&a,&b);原创 2021-01-31 20:58:22 · 163 阅读 · 0 评论 -
[PAT A1069 数字黑洞]
[PAT A1069 数字黑洞]Description:For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from原创 2021-01-31 20:40:16 · 113 阅读 · 0 评论 -
[PAT A1093 1093 Count PAT‘s]
[PAT A1093 1093 Count PAT's]Description:The stringAPPAPTcontains twoPAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now given any...原创 2021-01-31 17:35:57 · 122 阅读 · 0 评论 -
[PAT B1023 组个最小数]
[PAT B1023 组个最小数]Description:给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558。现给定数字,请编写程序输出能够组成的最小的数。输入格式:输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0、数字 1、……数字 9 的个数。整数间用一个空格分隔。10 个数字的总个数不超过 50,且至少原创 2021-01-27 18:21:40 · 89 阅读 · 0 评论 -
[PAT B1020 月饼]
[PAT B1020 月饼]Description:月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月原创 2021-01-27 17:59:04 · 110 阅读 · 0 评论 -
[递归 全排列&N皇后]
[递归 全排列&N皇后]Description递归求出全排列,如输出1到5的全排列Code【全排列】#include <cstdio>const int maxn=11;int n,P[maxn]={0}; //P存放已经排进来的数,n即为要求输出1~n的全排列bool hashTable[maxn]={false};void generateP(int index){ if(index == n+1){ //已原创 2021-01-27 16:14:51 · 98 阅读 · 0 评论 -
[PAT A1025 PAT Ranking]
[PAT A1025 PAT Ranking]Description:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged imm原创 2021-01-26 16:49:18 · 81 阅读 · 0 评论 -
[PAT B1009说反话]
[PAT B1009说反话]题目描述:给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过 80 的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用 1 个空格分开,输入保证句子末尾没有多余的空格。输出格式:每个测试用例的输出占一行,输出倒序后的句子。输入样例:Hello World Here I Come输出样例:Come I Here Wor原创 2021-01-25 18:31:30 · 109 阅读 · 1 评论 -
[codeup 5901 回文串]
【codeup 5901 回文串】题目描述读入一串字符,判断是否是回文串。“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。输入一行字符串,长度不超过255。输出如果是回文串,输出“YES”,否则输出“NO”。样例输入12321样例输出YESCODE#include<cstdio>#include<cstring>int main(){ char buffer[260]..原创 2021-01-25 17:13:03 · 81 阅读 · 0 评论 -
[PAT B1022 D进制的A+B]
[PAT B1022 D进制的A+B]输入两个非负 10 进制整数A和B(≤230−1),输出A+B的D(1<D≤10)进制数。输入格式:输入在一行中依次给出 3 个整数A、B和D。输出格式:输出A+B的D进制数。输入样例:123 456 8输出样例:1103CODE#include<cstdio>int res[32]={0};int main(){ int a,b,c; scan...原创 2021-01-25 16:54:17 · 88 阅读 · 0 评论 -
[codeup 1928日期差值]
[codeup 1928日期差值]题目描述有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天。输入有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD输出每组数据输出一行,即日期差值CODE#include<cstdio>#include<cmath>bool isLeap(int year){ return ((year%4==0 && year%100!=0)||(ye原创 2021-01-24 16:55:09 · 91 阅读 · 0 评论