ret

模拟通讯录

匿名 (未验证) 提交于 2019-12-02 23:55:01
c语言模拟 1 #include<stdio.h> 2 #include<string.h> 3 #define NAME_MAX 15 4 #define SEX_MAX 3 5 #define AGE_MAX 100 6 #define TEL_MAX 15 7 #define ADDR_MAX 20 8 #define PEOPLE_MAX 1000 9 10 typedef struct LINK 11 { 12 char name[15]; 13 char sex[SEX_MAX]; 14 int age; 15 char tel[TEL_MAX]; 16 char addr[ADDR_MAX]; 17 }linkman; 18 19 typedef struct PEOPLE 20 { 21 int num; 22 linkman count[1000]; 23 }*people; 24 25 26 //在通讯录里模糊搜索遍历到指定联系人 27 static int _search(people cou, const char *name) 28 { 29 int number = 0; 30 31 for (int i = 0; i < cou->num; i++) 32 { 33 if ((strstr((cou->count[i]).name, name) !=

Day 4

匿名 (未验证) 提交于 2019-12-02 23:52:01
1. 列表   用来存储大量数据 lst = [1,2,3,'你好','再见',False] print(lst) >>>[1, 2, 3, '你好', '再见', False]   2. 列表的增删改查    增 : lst = [1, 2, 3, '你好', '再见', False] lst.append('世界') #append 为追加,追加在最后边 print(lst) >>>[1, 2, 3, '你好', '再见', False, '世界']   lst = [1, 2, 3, '你好', '再见', False] lst.insert(2,'世界') #2 为插入的位置 '世界' 为插入的内容 print(lst) >>>[1, 2, '世界', 3, '你好', '再见', False]    lst = [1, 2, 3, '你好', '再见', False] lst.extend('今天是新的一天') #扩展 迭代添加 可迭代字符串 列表 print(lst) >>>[1, 2, 3, '你好', '再见', False, '今', '天', '是', '新', '的', '一', '天']#    删: lst = [1, 2, 3, '你好', '再见', False] del lst #删除整个列表    lst = [1, 2, 3, '你好', '再见

7 、 图论―连通性

匿名 (未验证) 提交于 2019-12-02 23:52:01
7.1 无向图关键点(dfs 邻接阵) //无向图的关键点,dfs 邻接阵形式,O(n^2) //返回关键点个数,key[]返回点集 //传入图的大小 n 和邻接阵 mat,不相邻点边权 0 #define MAXN 110 void search(int n,int mat[][MAXN],int* dfn,int* low,int now,int& ret,int* key,int& cnt,int root,int& rd,int* bb){ int i; dfn[now]=low[now]=++cnt; for (i=0;i<n;i++) if (mat[now][i]){ if (!dfn[i]){ search(n,mat,dfn,low,i,ret,key,cnt,root,rd,bb); if (low[i]<low[now]) low[now]=low[i]; if (low[i]>=dfn[now]){ if (now!=root&&!bb[now]) key[ret++]=now,bb[now]=1; else if(now==root) rd++; } } else if (dfn[i]<low[now]) low[now]=dfn[i]; } } int key_vertex(int n,int mat[][MAXN],int* key){ int ret

python_re正则表达

匿名 (未验证) 提交于 2019-12-02 22:51:30
#1、正则表达式使用: 用来匹配字符的普通字符:大多数字符和字母都会和自身匹配import re# s = "hello world"## print(s.find("llo"))# ret = s.replace("ll","xx")# print(ret)# print(s.split("w"))2元字符: . ^ $ * + ? { } [] | () \#. 任意匹配(除\n外)ret = re.findall("h...o","hello world")print(ret)#^ 从前匹配ret = re.findall("^h...o","hewdo world hexno")print(ret)#$ 从后匹配ret = re.findall("w..d$","wdifdhello sdwordwold")print(ret)#* 重复匹配ret = re.findall("ab*","hello world i come aback")print(ret) ret = re.findall("a+b","adsdfbadbababdjfn")print(ret)#? [0,1]ret = re.findall("a?b","abdsdfbadbababdjfn")print(ret)#{ } 贪婪匹配ret = re.findall("a{1,3}b",

浮点数运算的精确

自作多情 提交于 2019-12-02 22:31:58
var floatObj = function () { /* * 判断obj是否为一个整数 */ function isInteger(obj) { return Math.floor(obj) === obj } /* * 将一个浮点数转成整数,返回整数和倍数。如 3.14 >> 314,倍数是 100 * @param floatNum {number} 小数 * @return {object} * {times:100, num: 314} */ function toInteger(floatNum) { var ret = {times: 1, num: 0}; if (isInteger(floatNum)) { ret.num = floatNum; return ret } var strfi = floatNum + ''; var dotPos = strfi.indexOf('.'); var len = strfi.substr(dotPos + 1).length; var times = Math.pow(10, len); var intNum = parseInt(floatNum * times + 0.5, 10); ret.times = times; ret.num = intNum; return ret } /* * 核心方法

Educational Codeforces Round 74 #div2 ABCD

丶灬走出姿态 提交于 2019-12-02 16:20:51
A. Prime Subtraction Description 给两个数$x,y,x \gt y$,判断$x-y$是否为一个素数的整数倍 Solution 由唯一分解可得每个大于1的数都可以唯一分解为素数幂次之积,显然只需要判断x-y是否大于1即可 1 #include <algorithm> 2 #include <cctype> 3 #include <cmath> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 #include <map> 9 #include <numeric> 10 #include <queue> 11 #include <set> 12 #include <stack> 13 #if __cplusplus >= 201103L 14 #include <unordered_map> 15 #include <unordered_set> 16 #endif 17 #include <vector> 18 #define lson rt << 1, l, mid 19 #define rson rt << 1 | 1, mid + 1, r 20 #define LONG_LONG_MAX

11. 二叉查找树中搜索区间

送分小仙女□ 提交于 2019-12-02 15:10:49
11. 二叉查找树中搜索区间 给定一个二叉查找树和范围[k1, k2]。按照升序返回给定范围内的节点值。 样例 样例 1: 输入:{5},6,10 输出:[] 5 它将被序列化为 {5} 没有数字介于6和10之间 样例 2: 输入:{20,8,22,4,12},10,22 输出:[12,20,22] 解释: 20 / \ 8 22 / \ 4 12 它将被序列化为 {20,8,22,4,12} [12,20,22]介于10和22之间 /** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */ public class Solution { /** * @param root: param root: The root of the binary search tree * @param k1: An integer * @param k2: An integer * @return: return: Return all keys that k1<=key

AtCoder Beginner Contest 144 CDE题解

徘徊边缘 提交于 2019-12-02 13:34:13
Atcoder评测机没有ONLINE_JUDGE这个宏!! A,B巨水题 C - Walk on Multiplication Table Description 给一个数mul,求满足$x*y=mul \ && min\{x+y-2\}$ $mul \leq 10^{12}$ Solution 由均值不等式可知$x+y \geq 2*\sqrt{xy}$,给定xy,那么$min\{x+y-2\}$一定出现在$\sqrt{xy}$附近,扫一遍即可 1 #include <algorithm> 2 #include <bits/stdc++.h> 3 #include <cctype> 4 #include <cmath> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <cstring> 8 #include <ctime> 9 #include <iostream> 10 #include <map> 11 #include <numeric> 12 #include <queue> 13 #include <set> 14 #include <stack> 15 #if __cplusplus >= 201103L 16 #include <unordered_map> 17 #include <unordered_set

leetcode8 字符串转换整数

瘦欲@ 提交于 2019-12-02 13:03:51
<cctype> isdigit(char) 问题:在做乘法,加法前,先判断是否溢出 &&优先级大于== 然后教训: 考虑情况不周。比如3.14这样 然后解决办法 多自己搞几组测试 +1 1 -1 ... class Solution { public: int myAtoi(string str) { long long ret=0; long long cmp1=((long long)1<<31)-1; long long cmp2=-cmp1-1; int i=0; int flag=0; while(i!=str.length()) { if(str[i]==' '){ i++;} else if(str[i]!='-'&&!isdigit(str[i])&&str[i]!='+'){ return 0;} else { if(isdigit(str[i])) flag=1; else if(i<str.length()-1&&isdigit(str[i+1])) flag=str[i]=='+'?1:-1; else return 0; if(!isdigit(str[i])) i++; while(i<str.length()&&isdigit(str[i])) { ret=ret*10+(str[i]-'0'); if(ret>=cmp1&&(flag==1))

LEETCODE 7 整数反转

天涯浪子 提交于 2019-12-02 12:55:38
class Solution { public: int reverse(int x) { long long ret=0; long long cmp1=((long long)1<<31)-1; long long cmp2=-cmp1-1; while(x!=0) { ret=ret*10+x%10; if((ret>cmp1)||(ret<cmp2)) return 0; x/=10; } return ret; } }; 注意不能直接写1<<32,因为默认1是int的,然后-优先级高于<<,用括号吧 用long long cmp1=((long long)1<<31)-1; 这题感觉描述的有问题,我还以为是输入范围也在-2^32 - 2^32-1,结果错了一次.... #include<limits.h> #define INT_MAX 2147483647 #define INT_MIN (-INT_MAX - 1) 32位情况,C中int类型是32位的,范围是-2147483648到2147483647 。 来源: https://www.cnblogs.com/lqerio/p/11745846.html