char

代码面试之广义表

社会主义新天地 提交于 2020-03-01 06:57:57
广义表的基本概念 广义表(Lists,又称列表) 是线性表的推广。线性表定义为n>=0个元素a1,a2,a3,…,an的有限序列。线性表的元素仅限于原子项,原子是作为结构上不可分割的成分,它可以是一个数或一个结构,若放松对表元素的这种限制,容许它们具有其自身结构,这样就产生了广义表的概念。 广义表是n (n>=0)个元素a1,a2,a3,…,an的有限序列,其中ai或者是原子项,或者是一个广义表。通常记作LS=(a1,a2,a3,…,an)。LS是广义表的名字,n为它的长度。若ai是广义表,则称它为LS的子表。 抽象数据类型广义表的定义如下: ADT Glist { 数据对象: D={ei | i=1,2,..,n;n>=0 ; eiÎAtomSet 或ei ÎGlist, AtomSet为某个数据对象} 数据关系:R1={< ei-1, ei > | ei-1 , ei ÎD,2<=i<=n} 基本操作: InitGList( &L); 操作结果:创建空的广义表L。 CreateGList(&L,S); 初始条件:S是广义表的书写形式串。 操作结果:由S创建广义表L。 DestroyGList(&L); 初始条件:广义表L存在。 操作结果:销毁广义表L。 CopyGList( &T,L); 初始条件:广义表L存在。 操作结果:由广义表L复制得到广义表T。 GListLength

一道题目

耗尽温柔 提交于 2020-03-01 04:49:28
given a string ,return the longest substring that contains at most two characters. extern "C" char *SubStringWithAtMost2Chars(char * pStr, int len) { if(len <= 2) return pStr; char ch1, ch2; int ch1Index= -1, ch1Cnt = 0, ch2Cnt = 0; char lastCh1 = '0', lastCh2 = '0'; int lastCh1Index = -1,lastCh2Index = -1, lastCh1Cnt = 0, lastCh2Cnt = 0; for(int i = 0;i< len; i++) { if(lastCh1Cnt == 0) { lastCh1 = pStr[i]; lastCh1Index = i; lastCh1Cnt ++; } else { if(lastCh2Cnt == 0) { if(pStr[i] == lastCh1) { lastCh1Cnt++; } else { lastCh2 = pStr[i]; lastCh2Cnt++; lastCh2Index = i; } } else { if(pStr[i] ==

汉诺塔的递归实现

梦想与她 提交于 2020-03-01 03:30:16
求解汉诺塔的问题(n, a, b, c),即将N个盘子从起始柱(标记为“a”)通过借助柱(标记为“b”)移动到目标柱(标记为“c”),并保证每个移动符合汉诺塔问题的要求。 输入格式: 输入为一个正整数N,即起始柱上的盘数。 输出格式: 每个操作(移动)占一行,按柱1 -> 柱2的格式输出。 输入样例: 3 输出样例: a -> c a -> b c -> b a -> c b -> a b -> c a -> c #include<cstdio> #include<cstdlib> #include<cstring> void ta(int n,char A,char B,char C); int main() { int n; scanf("%d",&n); ta(n,'a','b','c'); return 0; } void ta(int n,char A,char B,char C) { if(n==1) printf("%c -> %c\n",A,C); else { ta(n-1,A,C,B); printf("%c -> %c\n",A,C); ta(n-1,B,A,C); } } 你说递归不香吗?何必为难自己。 来源: CSDN 作者: qq_34928355 链接: https://blog.csdn.net/qq_34928355/article/details

Xcode中macos开发导入opencv2

你说的曾经没有我的故事 提交于 2020-03-01 03:17:05
Undefined symbols for architecture x86_64: "_AVCaptureSessionPresetMedium", referenced from: CvCaptureCAM::startCaptureDevice(int) in opencv2(cap_avfoundation.o) "_AVFileType3GPP", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o) "_AVFileTypeAppleM4V", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int, double, CvSize, int) in opencv2(cap_avfoundation.o) "_AVFileTypeMPEG4", referenced from: CvVideoWriter_AVFoundation::CvVideoWriter_AVFoundation(char const*, int,

PTA 练习8-8 移动字母 (10分)

耗尽温柔 提交于 2020-03-01 03:13:18
void Shift ( char s [ ] ) { char a [ MAXS ] , * p ; p = & s [ 3 ] ; int i , k = 0 ; int l = strlen ( s ) ; for ( int i = 0 ; i < 3 ; i ++ ) a [ i ] = s [ i ] ; for ( i = 0 ; i < l - 3 ; i ++ ) s [ i ] = * ( p + i ) ; for ( int j = i ; j < l ; j ++ ) s [ j ] = a [ k ++ ] ; } 来源: CSDN 作者: superman_lile 链接: https://blog.csdn.net/superman_lile/article/details/104581813

day3_python_learn for mofan

你。 提交于 2020-03-01 01:44:00
Today I have practiced my oral english. so so I may need to use it mpre frequently Seek joy amidst sorrow set char_list = [ 'a' , 'b' , 'v' , 'v' , 'v' , 'e' , 'r' , 'f' ] ##sentence='Welcome to our home' ##print(type(set(char_list))) ###type is class set ##print(set(char_list)) ###capital letters or lowercase letters are different ##unique_char=set(char_list) ##unique_char.add('a') ##print(unique_char) ##unique_char.clear() #delate all ##print(unique_char.remove('a')) ##print(unique_char.discard('y')) #error return something but not the list set1 = char_list set2 = { 'a' , 'c' , 's' , 'w' ,

c语言数字转字符串

落花浮王杯 提交于 2020-03-01 01:43:13
对下面代码的一些细节,解释下为什么那么做。 1. char buf[sizeof(int) * 8 + 1] = ""; 这个buf的作用是缓存中间结果,长度没有写死。好处是不同的平台上这段代码都可以执行。 2. if (base < 2 || base > 36) 该判断检查用户传入的进制数是否合法。base < 2 主要过滤负数和0和1。base > 36的意义是在超过10进制的数里,是用字母a表示10的。以此类推z可以表示36。在只使用ascii字符表示大于10的数时,最大的表示值是36,超过这个值就不能表示。 3. uval = -val; 这各写法可以避免一个潜在的坑。当val为int值为INT_MIN时 -val会溢出。表象为-val 的值还是INT_MIN,还是个负数 4.至于为什么用一个无符号整数与一个>0的int进行整除与取余 uval % base uval /= base 因为c语言的标准里没有规定x / y当有一个值为负数时,结果该向x坐标轴的左侧靠近(向0取整) 还是向侧靠近(负无穷) 它只规定了 (x / y) * y + (x % y) = x -14 /5 的结果可以是 -2 或者 -3 至为正数为啥没有两个结果。本人只是用了几个值进行了验证。。 好了贴代码: #include <stdio.h> #include <limits.h>

C语言基础学习基本数据类型-Char类型

北战南征 提交于 2020-03-01 01:21:48
char类型 char类型用于储存字母和标点之类的字符。但是在技术实现上char却是整数类型。为了处理字符,计算机使用一种数字编码,用特定的整数表示特定的字符。字符变量输入输出用%c符号。定义语法如下: char 变量名 = '一个字符值'; char类型占一个字节,所以一个char变量不能存放一个中文汉字(一个汉字占2个字节)。这里单个字符必须用单引号' ',如果使用双引号,编译器将其视为字符串,我们将在后面的博文讲到字符串。 更多学习内容,就在码芽网http://www.mayacoder.com/lesson/index 看个实例和输出吧: 来源: oschina 链接: https://my.oschina.net/u/2814141/blog/742989

实现linux的ls命令,可带参数

若如初见. 提交于 2020-02-29 19:47:56
两个重点: opendir:DIR *opendir(const char *name), 传文件名,返回一个指针,指向目录序列。头文件:#include <sys/types.h> readdir:struct dirent *readdir(DIR *dirp), 把opendir的返回值传过来, 返回值为一个结构体。头文件 #include <dirent.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h>//获取时间 #include<sys/stat.h>//返回一个包含文件属性的结构体 #include<unistd.h>//调用系统原语 #include<sys/types.h>//一些数据类型,如pid_t进程ID #include<linux/limits.h>//限制数据类型边界 #include<dirent.h>//打开目录读取目录关闭目录,成功则返回指针 #include<grp.h>//组文件 #include<pwd.h>//口令文件 #include<errno.h>//查看错误代码 #define PARAM_NONE 0 //无参数 #define PARAM_A 1 //-a :显示所有文件 #define PARAM_L 2 //-l

C语言学习(3reverse倒置)

有些话、适合烂在心里 提交于 2020-02-29 19:45:12
使用函数对字符串进行倒置。 # include <stdio.h> # include <string.h> void swap ( char * a , char * b ) { char c ; c = * a ; * a = * b ; * b = c ; } void reverse ( char * str ) { int i = 0 , L = strlen ( str ) ; for ( i = 0 ; i < int ( L / 2 ) ; i ++ ) { swap ( & str [ i ] , & str [ L - i - 1 ] ) ; //在交换数组元素时,使用swap1(a+i, a+j)或者swap1(&a[i], &a[j]); } } void main ( ) { char str [ 501 ] ; while ( scanf ( "%s" , str ) != EOF ) { reverse ( str ) ; printf ( "%s" , str ) ; } } 来源: CSDN 作者: qq_36979673 链接: https://blog.csdn.net/qq_36979673/article/details/104574591