- 博客(38)
- 资源 (1)
- 收藏
- 关注

原创 gdb 问题
##########问题二gdb 调试 no stack源程序:#include <stdio.h>void swap(int* a,int* b){ int t=*a; *a=*b; *b=t;}//sizeof() 获得变量占的字节数目,其中第一个字节的地址称为变量的地址 int main(){ int a = 3,b = 4; swap(&a,&b); printf("%d %d\n",a,b); return 0;}执行过程gcc t
2020-10-23 10:53:22
2571
1
原创 Git实现对ns3的版本控制
下载地址将该压缩包解压后的得到cd ns-3-devgit tag 查看可用版本接下来我切换到ns-3.30, 并建立分支git checkout ns-3.30git checkout -b outcast-testgit log --decorate git branch 查看当前分支状况至此便成功建立了分支, 并且master 和 outcast-test是独立的两个分支,以后若需要在另外的ns3版本上测试代码, 按照以上步骤即可。注意: 由于master 和 out.
2021-04-14 16:01:43
324
原创 分子量 UVa1586
2021年代码更简洁,并且不失可读性2020年12月代码// 错误之处 忘记了 从字符串中读数字 abc11 只能一位一位的读,不能一下就读到11 //以下为AC代码 #include<iostream>#include<bits/stdc++.h> using namespace std;double n[4] = {12.01,1.008,16.00,14.01};vector<int> v;int main(){ int T; cin &g
2021-04-04 18:56:53
149
原创 NS3问题合集
1.修改源代码后eclipse无法识别报错:“Invalid arguments ’ Candidates are: ”Project -> c/c++ Index -> Rebulid.ps:我最开始尝试了直接编译源代码, 仍然报错(浪费了几十分钟)。故发现了上面的才是正确做法...
2021-03-30 20:53:52
231
原创 整型十进制数转化为ip地址(ipv4)
注: 简单修改tmp参数即可更换十进制ip#include <iostream> #include <vector>#include <cmath>#include <algorithm>using namespace std;int main(){// int tmp = 167772417; int tmp = 167772161; int ip[4], n = 0, last = 4, count = 0; vector<int
2021-03-09 12:16:16
1440
原创 The Dole Queue - UVa 133
思路: AOCPC写的很完善了,请参考书本收获: 合并go函数是我的难点,理解了很久才堪堪了解。 多练!!AC代码如下:#include <iostream> using namespace std;#define maxn 25int n, k, m, a[maxn];int go(int p, int d, int t){ //p代表当前位置 d代表顺时针/逆时针 t代表走的步数 while(t--){ do{ p = (p + d + n - 1) % n +
2020-12-28 19:24:50
112
原创 All in All - UVa 10340
收获: 无#include <iostream>using namespace std;int main(){ string s, t; while(cin >> s >>t){ int pos = 0; //已匹配的位置 for(int i=0; i<t.length(); i++){ if(s[pos] == t[i]) pos++; } if(pos == s.length()) cout << "Yes" <
2020-12-25 14:57:02
121
原创 Repeating Decimals - UVa 202
短小精悍收获:理解了除法的真谛,重要的是余数。商? 附赠品罢了初见时的AC#include <iostream>using namespace std;int main(){ int m,n,i; while ((cin>>m>>n)) { int a[10000]= {0},b[10000]= {0}; int k,cycle,k1,flag=0; k=m%n; k1=
2020-12-24 19:44:07
168
2
原创 谜题Puzzle-UVa227
思路:看原文理解,直译收获:阅读英文的能力、getline()的注意点 1:用字符串 2.getchar()吸收空格。AC代码#include<iostream>using namespace std;char ans[30][30];int main(){ int i, j, kase = 0, x, y; //x,y空白格的位置 string s; char ins; while(getline(cin,s)){ if(s[0] == 'Z') break;//结束
2020-12-24 14:10:04
158
原创 纵横字谜的答案UVa232
通点:PE(Presentation Error)/*注意原题的最后一句话 Separate output for successive input puzzles by a blank line. if(kase) cout << endl; 解决PE的关键 printf("puzzle #%d:\n",++kase); */#include<iostream>#include<cstring> using namespace std;int a[
2020-12-23 21:25:17
214
原创 DNA序列UVa1368--AC代码
一遍过的,别提有多开心了。待改进部分: 两个switch-case导致代码冗长//存hamming distance 解决 //存几个最小的下标,然后用一个函数找出字典序最小的。 //大失误 ,题目意思理解错误 题目要求自己构造一个最小,而不是从已有的选一个最小。!!!! //AC 代码 #include<iostream>#include<vector>#include<cstring>#include<algorithm>using
2020-12-21 18:32:13
160
2
原创 排列 习题2-6(permutation)
·```cpp/*a~i 这9个字母之间是存在加减关系的,所以可以使用加减法算出d~i 从而减少循环的次数。/#includeusing namespace std;int main(){int d,e,f,g,h,i;for(int a=1;a<=9;a++) //从 111 遍历到 999for(int b=1;b<=9;b++)for(int c=1;c<=9;c++){int sum1 = a100+b10+c;int sum2 = sum12;int
2020-12-18 12:47:51
181
原创 《算法竞赛入门经典》习题2-5 分数化小数(Decimal)
前言:核心思想就是模拟手算的除法我的思想:使用数组讲小数部分存储,输入c位,计算c+1,判断是否需要舍入。 考虑了 小数位为99999的情况,所以使用数组存储而不是直接输出的方法更安全。ps:我并不知晓使用数组是否有必要,希望能有好心人告知,不胜感激此代码苦于没有找到可以提交的地方,若有同学看到,希望能帮我提交一下并告知,感激不尽!/*输入样例:1 6 42 3 12 3 22 3 31 7 11 7 21 7 3 1 7 41 7 20 0 0 0*/#include
2020-12-18 12:32:33
159
2
原创 模块module的概念
在C语言中,我们会把重复使用或具有某项功能的代码封装成一个函数,将拥有相关功能的多个函数放在一个源文件,再提供一个对应的头文件,这就是一个模块。使用模块时,引入对应的头文件就可以。...
2020-11-26 14:32:57
1592
原创 L1-020 帅到没朋友 (20分)----气死我了
我的错误思路:用set 数组 将每个朋友圈分开存储,然后等待查询。缺点:题目理解能力不足,关键信息把控不到位。!!!多练。错误代码#include <iostream>#include<cmath>#include <algorithm>#include<vector>#include <cstring>#include<cmath>#include<set>using namespace std;se
2020-10-28 21:58:54
306
原创 L1-016 查验身份证 (15分)---求助,恳请大家帮助查错
我的代码 得了14分,还差一分的一个样例不通过,恳求大家帮忙看看哪个地方没有考虑到。#include<iostream>#include<cmath> #include<cstring>#include<vector>using namespace std;int weight[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char M[]="10X98765432";vector<string>
2020-10-28 20:39:42
135
原创 最大公约数相关问题--L1-009 N个数求和 (20分)
我的WA垃圾代码: ----引以为戒缺点: 冗长,不简洁,难以理解.#include <iostream>#include<vector>#include<cmath>#include<algorithm>using namespace std;long fa=0,fb=0;void max_divisor(long * a,long * b){ //求最大公约数,将分子,分母最简化. int ta=fabs(*a),tb=fabs(
2020-10-26 10:39:47
137
原创 L1-006 连续因子 (20分)
个人理解,解释都在代码里边了.#include <iostream>#include <cstdio>#include <vector>#include <cmath>#include <cstring>using namespace std;int main() { int n; cin>>n; //通过求13! 发现超过了2^31 所以连续最长因子不超过11 //类似的需要求[子....的] 一般都通过暴
2020-10-25 16:14:01
117
原创 L1-035 情人节 (15分)
我的问题:没有注意到题目中不知道输入字符串的数量,在结构体stu中我限定了字符串s的大小,这里导致了错误。在main中的while添加一个判断即可。#include <iostream>#include <set>using namespace std;struct stu{ string s[15];}; int main() { stu ans; string t; cin>>t; int num=0; while(t!="."){ /
2020-10-24 16:33:23
146
原创 STL:set
c++中set是自动有序的:示例代码:#include <iostream>#include <set>using namespace std;set<int> ans; int main() { int a=1234; while(a){ ans.insert(a%10); a/=10; } for(set<int>::iterator it=ans.begin(); it!=ans.end(); it++) cout<
2020-10-24 14:35:59
83
原创 L1-032 Left-pad (20分)
题目描述:L1-032 Left-pad (20分)根据新浪微博上的消息,有一位开发者不满NPM(Node Package Manager)的做法,收回了自己的开源代码,其中包括一个叫left-pad的模块,就是这个模块把javascript里面的React/Babel干瘫痪了。这是个什么样的模块?就是在字符串前填充一些东西到一定的长度。例如用*去填充字符串GPLT,使之长度为10,调用left-pad的结果就应该是******GPLT。Node社区曾经对left-pad紧急发布了一个替代,被严重吐槽。
2020-10-24 13:44:16
138
原创 L1-030 一帮一 (15分)
问题描述:“一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的异性学生分为一组。输入格式:输入第一行给出正偶数N(≤50),即全班学生的人数。此后N行,按照名次从高到低的顺序给出每个学生的性别(0代表女生,1代表男生)和姓名(不超过8个英文字母的非空字符串),其间以1个空格分隔。这里保证本班男女比例是1:1,并且没有并列名
2020-10-23 13:36:57
68
原创 L1-002 打印沙漏
练的太少了,不会处理输出符号这类题,多练!!!本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印***** *** * ********所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。输入格式:输入在一行给出1个正整数N(≤1000)和一个符号,中间以空格分隔。
2020-10-21 22:07:19
434
原创 c++ STL(个人用)
Vetcorvector<string> v; // 无参数版vector<string> v2(10); //初始容量为 10 的 vector,每个元素为都为 string 的默认值vector<string> v3(10,"abc"); //初始容量为 10,且每一个元素都为 abc如果要访问或者修改 vector 的内容,可以用如下的函数:vector<int> v;v.push_back(10);
2020-10-11 14:48:57
118
原创 线性表应用-栈educoder
在cpp中存储是个大问题,没有new,函数在跑完后就释放了所有其产生的内存,导致在函数里加上去的新栈顶也被清除,最后什么都没有发生,sk还变成了一个野指针—来自educoder评论//为p分配内存空间很重要intStack p=new node;void push(intStack &sk, int n){ // 请在此添加代码,补全函数push /********** Begin *********/ intStack p=new node; p->
2020-10-08 22:00:21
456
原创 删除指定位置的结点educoder
总结: 注意给出待删除结点i的值不能超过索引(0~n-1),不能低于索引0.这里只需要区分是否删除头结点 和 非头结点.node * delAt(node * h, int i){ // 请在此添加代码,补全函数delAt /********** Begin *********/ if(i<0) return h; // node* p=NULL,*q = h; for(int j=0; j<i; j++){ if(q->next
2020-10-08 16:36:07
484
原创 排序构建线性表educoder
花了38分钟才写出来,多练多练!!!总结:用两个结点夹逼出待插入节点的位置 :定位好插入点后,当 p 为“NULL”时,插入点是链表头部;当 q 为“NULL”时,插入点是链表尾部;否则,插入点为 p 和 q 指向的两个结点之间。#include <iostream>using namespace std;// 定义结点结构struct node{ int data; // 数据域 node * next; // 指针域,指向下一个结点};// 函数in
2020-10-08 14:00:40
1286
1
原创 顺序构建线性表(尾插入)educoder
总结:很久没有遇到链表相关的题目,导致遗忘了处理链表时应该判断头结点是否为空,漏掉这一步会导致无法形成链。#include <iostream>using namespace std;// 定义结点结构struct node{ int data; // 数据域 node * next; //指针域,指向下一个结点};// 函数insertTail:链表尾部插入// 参数:h-链表头指针,t-指向要插入的结点// 返回值:插入结点后链表的首结点地址nod
2020-10-08 10:15:20
1240
原创 书籍排序educoder
详细题目见educoder总结:还是练题练得太少,本题的重点在于排序,综合考虑到2个因素来排序,价格优先级最高,其次书名的字典序。#include <string.h>#include <iostream>using namespace std;//请在此添加代码,实现书籍数据的输入、排序和输出/********** Begin *********/typedef struct book{ char name[55]; float price;}mybook;
2020-10-07 16:48:32
2244
原创 子串出现的次数educoder
认真做完前面几个实验,这道题就是水到渠成。// 包含字符串函数库#include <string.h>#include <iostream>using namespace std;int frequency(char * substr, char * str);int main(){ char sub[128],str[1024]; cin.getline(sub,128); // 输入子串 cin.getline(str,1024)
2020-10-07 11:20:23
1517
原创 选出字符串中的数字educoder
1.判断是否在第一个数字之前含有负号2.找出数字串#include <iostream>using namespace std;void extractNum(char * str);int main(){ char s[1024]; cin.getline(s,1024); // 输入一行字符 extractNum(s); // 调用extractNum函数,选出数字 cout<<s<<endl;
2020-10-07 11:01:07
2395
原创 去掉字符串首尾空格educoder
[重要1 和 重要2] 这两个地方都是我以前没有见过的,记下来。#include <iostream>using namespace std;char * trim(char * str);int main(){ char s[1024]; // 定义存储字符串的一维字符数组 // 输入一行字符,可以包含空格 // 输入的字符串存入s中,最多读取个字符,后面自动加上'\0' cin.getline(s,1024); cout...
2020-10-07 10:34:16
757
2
原创 朋友圈点赞educoder
// 请在此添加代码,通过统计朋友圈点赞,统计个人爱好功能/********** Begin *********/#include<iostream>using namespace std;int res[1000+5]={0};int main(){ int N; cin >> N; //用户点赞的文章数量 int t,mark; while(N--){ cin >> t; //当前文章标签数 for(int i=0; i<t
2020-10-06 22:48:16
862
1
原创 队列变换-educoder
我还是练题练得太少了,一开始不仅没有想到是要按每一行处理,我还想着直接一次性处理一列, 想了很久之后明白:1. 每次处理一行2. 用2个数组,book[]标记出每个元素移位后应该在的位置,res[]标记移位后每个位置的元素值#include <iostream>using namespace std;// 函数rotateLeft:矩阵循环左移// 参数:a-100*100的二维数组,用来存储n行n列的数组(n<100),存储在其~n-1行和~n-1列,// m-循环左移的位
2020-10-06 22:22:23
1475
2
原创 解放你的鼠标
敲下home ,定位到行首;shift+end,选中光标所在行的所有内容,delete。shift+方向键的上,下,左,右; 可以选中更多内容,delete。
2020-02-11 22:43:30
170
原创 L1-003 个位数统计 (15分)/PTA
给定一个 k 位整数 N=dk−1 10k−1 +⋯+d1 101 +d0 (0≤di ≤9, i=0,⋯,k−1, dk−1 >0),请编写程序统计每种不同的个位数字出现的次数。例如:给定 N=100311,则有 2 个 0,3 个 1,和 1 个 3。输入格式:每个输入包含 1 个测试用例,即一个不超过 1000...
2019-12-25 13:13:18
510
原创 蛇形方阵/回旋距阵
#include <iostream>#include<string.h>using namespace std;#define maxn 20int a[maxn][maxn];int main(){ int n,x,y,tot=0; //tot标志变量 cin>>n;// memset(a,0,sizeof(a));//...
2019-12-24 22:21:20
205
原创 开关灯问题
#include <iostream>#include<string.h>using namespace std;int main(){ int n,k,a[1010]; int first=1; memset(a,0,sizeof(a));//或者 int a[1010]={0}; cin>>n>>k; ...
2019-12-24 21:34:19
187
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人