随笔分类 -  编程练习题(C++实现)

摘要:从bin文件指定位置开始读取固定数目字符,输出打印结果 1、结果通过输入参数返回 #include <string.h> #include <stdio.h> #define tcon_path "/data/tcon.bin" int PANEL_TCON_BIN_VERISION(const c 阅读全文
posted @ 2022-03-08 10:20 victorywr 阅读(314) 评论(0) 推荐(0)
摘要:#include<bits/stdc++.h> using namespace std; int main(void){ int n; string s; string p = "wang"; while(cin >> s) { int cnt = 0; size_t found = s.find( 阅读全文
posted @ 2020-08-20 19:35 victorywr 阅读(610) 评论(0) 推荐(0)
摘要:#include<iostream> #include<stdio.h> #include<string.h> #include<math.h> using namespace std; int fact(int n,int p) //十进制转为任意进制 (n是十进制数,p是要转化进制选择) { i 阅读全文
posted @ 2020-08-16 16:18 victorywr 阅读(793) 评论(0) 推荐(0)
摘要:如输入:3 》》》二进制101 所以 输出 》》》2 #include<iostream> #include<string> using namespace std; void count_byte(unsigned int x) { unsigned int tmp = 1; int countx 阅读全文
posted @ 2020-08-15 20:38 victorywr 阅读(821) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; void shiftone(string &s, int m) { while (m--) { char t = s[0]; int len = s.size(); for (int i = 1; i < len; ++ 阅读全文
posted @ 2020-08-15 20:31 victorywr 阅读(658) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <string.h> int main(){ char *token = "she"; FILE *fp = fopen("test.txt","a+"); char buf[1024]; char *p; int s=-1,len=strle 阅读全文
posted @ 2020-08-14 17:11 victorywr 阅读(564) 评论(0) 推荐(0)
摘要:int *(*testState) = new int*[n];for (int i = 0; i < n; ++i){ testState[i] = new int[w]; for (int j = 0; j < w; ++j) { testState[i][j] = 1; }} 阅读全文
posted @ 2020-08-13 09:34 victorywr 阅读(365) 评论(0) 推荐(0)
摘要:大概思路: 一个map<string,int>存储输入的字符内容以及输入的次数,对次数进行判断,输出少于指定次数的字符串: #include<iostream> #include<map> #include<string> using namespace std; int main() { int 阅读全文
posted @ 2020-08-11 10:39 victorywr 阅读(317) 评论(1) 推荐(0)
摘要:题目描述:给定一个长度为n的整数数组a,元素均不相同,问数组是否存在这样一个片段,只将该片段翻转就可以使整个数组升序排列。其中数组片段[l,r]表示序列a[l], a[l+1], ..., a[r]。原始数组为 a[1], a[2], ..., a[l-2], a[l-1], a[l], a[l+1 阅读全文
posted @ 2020-07-22 11:13 victorywr 阅读(239) 评论(0) 推荐(0)
摘要:约瑟夫问题是个有名的问题:N个人围成一圈,从第一个开始报数,第M个将被杀掉,最后剩下一个,其余人都将被杀掉。例如N=6,M=5,被杀掉的顺序是:5,4,6,2,3。最后只有1存活。 思路:用环链表实现,每计数到M,删除该处的节点,直到最后仅剩一个节点,输出节点的值,就是存活的人。 #include< 阅读全文
posted @ 2020-07-19 15:00 victorywr 阅读(225) 评论(0) 推荐(0)
摘要:一、时间复杂度为N,空间复杂度为1(遍历整个栈元素,逐个比较,找出最小值) 二、空间复杂度为N,时间复杂度为1(创建一个辅助栈,栈顶存放当前已入栈的最小值) 例如我们要把数组 arr = {2, 1, 3} 都放⼊栈中,则存放过程如下: 1、⾸先 push 2。由于刚开始 stack 和 helpe 阅读全文
posted @ 2020-07-19 11:21 victorywr 阅读(296) 评论(0) 推荐(0)
摘要:算法逻辑: 1.新数据会插入到链表头 2.当缓存数据被访问,将该缓存数据移到链表头部 3.当新数据插入时达到缓存上限了,将尾部数据删除掉(也就是最近最少使用的),新数据放在头部。 利用Map进行节点定位,时间复杂度大大降低,利用双向链表实现LRUCache逻辑,便于频繁实现首尾节点的移除和更新。 # 阅读全文
posted @ 2020-07-18 10:27 victorywr 阅读(577) 评论(0) 推荐(0)
摘要:1、问题描述:一只青蛙一次可以跳上1级台阶,也可以跳上2级。求该青蛙跳上一个n级的台阶总共有多少种跳法。 例: 台阶n=0 输出:0 台阶n=2 输出:2 台阶n=3 输出:3 台阶n=4 输出:5 台阶n=7 输出:21 int step(int a) { if (a <= 2) //如果a<=2 阅读全文
posted @ 2020-07-12 17:09 victorywr 阅读(212) 评论(0) 推荐(0)
摘要:struct A { char a1; short a2; int a4; char *p1; }; 这么个结构体,如何计算它在内存里占用的大小? 这里涉及到的就是计算机内部数据存储原则,需要对齐,若是按常规的64位机器:char型=1Byte,short =2Byte,int=4Byte,指针8B 阅读全文
posted @ 2020-07-02 16:33 victorywr 阅读(546) 评论(0) 推荐(0)
摘要:1:创建一个单链表 2:显示打印一个单链表 3:单链表长度计算 4:查找指定元素,返回该元素在链表中的位置 5:查找指定节点,返回特定位置的节点,并打印节点出的数据 6:插入元素到单链表的指定位置,返回插入后的链表 7:删除节点,给定节点位置,删除该处的数据,返回删除该节点的链表 8:反转链表,将链 阅读全文
posted @ 2020-06-26 16:34 victorywr 阅读(361) 评论(0) 推荐(0)
摘要:例: 输入:423dxqjkx81 输出:12348 思路:首先通过随机字符串的每个字符进行Ascall码进行分析,通过Ascall筛选出数字部分并将数字的字符转化为数字,保存到一个数组中,利用冒泡排序的子函数对该数组进行排序,输出结果。 程序如下: #include <iostream> #inc 阅读全文
posted @ 2020-04-22 21:32 victorywr 阅读(1033) 评论(0) 推荐(0)
摘要:例: 输入字符串:qweqweasdlmn 输出字符串:qweasdlmn #include <iostream> #include<cstring> using namespace std; string remove_same(string str) { size_t subpos,sublen 阅读全文
posted @ 2020-04-22 16:49 victorywr 阅读(2991) 评论(0) 推荐(0)
摘要:要求:给定一个目标值target,一个数组,数组里任意两个数求和,和若等于target,输出这些组合的下标,不重复计算 例:array=[1,2,5,,6,3] target=7 输出: 0,3(0是元素1的下标,3是元素6的下标)(不重复计算:1+6=7 , 6+1=7,只输出一次下标) 1,2 阅读全文
posted @ 2020-04-22 16:30 victorywr 阅读(828) 评论(0) 推荐(0)