strlen

【算法】高精四则运算

匿名 (未验证) 提交于 2019-12-03 00:40:02
高精度加法 #include<iostream> #include<cstring> #include<cstdio> using namespace std; char a[200],b[200]; int a1[200],b1[200],c1[200]; int l1,l2,l3; int main() { scanf("%s",a); scanf("%s",b); l1=strlen(a); l2=strlen(b); for(int i=0;i<=strlen(a)-1;i++) a1[l1-i]=a[i]-48; for(int i=0;i<=strlen(b)-1;i++) b1[l2-i]=b[i]-48; int k=0; l3=1; while(l3<=l1||l3<=l2) { c1[l3]=a1[l3]+b1[l3]+k; k=c1[l3]/10; c1[l3]%=10; l3++; } c1[l3]=k; if(c1[l3]==0) l3--; for(int i=l3;i>=1;i--) cout<<c1[i]; } 高精度减法 (只支持两个正整数) #include<iostream> #include<cstring> #include<cstdio> using namespace std; char a[200],b[200],n[200];

ue4同c#通信时的中文乱码问题

匿名 (未验证) 提交于 2019-12-03 00:34:01
本文讨论C#同ue4进行通信,出现的中文乱码情况,其他语言类似。 本文分两种情况讨论, 1.C#向ue4发送string 在C#发送string时,要先区分发送的字符串中是否包含中文,判断方法很简单,如下: private bool IsPureAnsi(string str) { for (int i = 0; i < str.Length; ++i) { if ((int)str[i] > 127) { return false; } } return true; } 当string中不包含中文时,每个字符占1个字节,string前要先发送string的长度,占4个字节,string结束要加'\0'结尾(c传统) 当string中包含中文时,每个字节占用2个字节,格式同上( 注意string长度无需*2,而且string长度要取反 , string结尾需要两个字节的'\0' ) 具体代码如下: public byte[] StringToBytes(string str) { Stream stream = new MemoryStream(); if (this.IsPureAnsi(str)) { byte[] strLenBytes = System.BitConverter.GetBytes(str.Length + 1); stream.Write

C++ 重写String类

匿名 (未验证) 提交于 2019-12-03 00:21:02
codeblocks gcc version 4.9.2 (tdm-1) 构造方法 描述 String(char *s,int len) 构造方法初始化数据 成员方法 描述 char *getStr() 获取当前的String(打印) int getLength() 获取当前String的长度 char *Strcpy(char *s) 字符串的复制 char *Strcat(char *s) 字符串的连接 int Compare(char *b) 字符串的比较 char *substring(int sub_start,int sub_end) 指定起始终止位置求子串 void exchange(char *s) 字符串的交换 int BF_Find_String(char *s) 在当前字符串String中查找子串 int indexOf(char index) 查找某字符在当前String中第一次出现的位置 void toUpperCase() 字符串小写转大写 void toLowerCase() 字符串大写转小写 char *trim() 消除字符串中的空格 char *SplitStr() 消除{,!”“#$%&’()*+,-./}的字符 void set(int index,char letter) 在指定字符串的指定位置添加某字符 #include<

StringUtils里的isEmpty方法和isBlank方法的区别

匿名 (未验证) 提交于 2019-12-03 00:18:01
isEmpty public static boolean isEmpty(String str) { return str == null || str.length() == 0;} isBlank public static boolean isBlank(String str) { int strLen; if (str != null && (strLen = str.length()) != 0) { for(int i = 0; i < strLen; ++i) { if (!Character.isWhitespace(str.charAt(i))) { //判断字符是否为空格、制表符、tab return false; } } return true; } else { return true; } } 通过以上代码我们可以看出: 是否为空和是否存在 为判断依据。 isEmpty的基础上进行了为空的判断 。(一般更为常用) 大家可以下面的例子取体会一下。 StringUtils.isEmpty("yyy") = false StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isBlank("yyy") = false StringUtils.isBlank("")

字符串、字符和字节

匿名 (未验证) 提交于 2019-12-03 00:05:01
C语言中没有显示的字符串数据类型,字符串以字符串常量或者字符数组的形式出现,字符串常量适用于那些程序不会对它们进行修改的字符串。所有其它字符串都必须存储于字符数组或动态分配的内存中。 字符串 是一串零个或多个字符,并且以一个位模式为全0的NULL字节结尾。 字符串所包含的的字符内部不能出现NULL字节。 NULL字节是字符串的终结符,但它并不是字符串的一部分,所以字符串的长度并不包含NULL字节。 字符串函数的声明都在 string.h 头文件中。 字符串的长度就是它所包含的字符个数,通常使用函数 strlen 来计算字符串的长度。 sizet_t strlen ( char const * string ); size_t 定义在 stddef.h 中,它是一个无符号整数类型。 在表达式中使用无符号数可能导致不必要的结果,如下: if ( strlen ( x ) >= strlen ( y ))... if ( strlen ( x ) - strlen ( y ) >= 0 )... 第二条语句的结果永远为真,因为strlen(x)、strlen(y)的返回值都是无符号数,所以>=左边是无符号数,无符号数不可能小于零。 最常用的字符串函数都是不受限制的,就是说它们只是通过寻找字符串参数结尾的NULL来判断它的长度。在使用这些函数时,必须要 保证结果字符串不会溢出内存。

Checking string length with strlen

穿精又带淫゛_ 提交于 2019-12-02 23:56:28
问题 I have this code, i want it to check if the length is NOT 32 or 40. The code below only checks if the word is 32 or 40 in length. <? $name = mysql_real_escape_string($_POST['dgt']); $len = strlen($name); if (!($len == "32" or $len == "40")){ print "This is not a name."; } else { echo 'This is a name'; ?> 回答1: if ($len != 32 && $len != 40) try that out 回答2: What about if($len != 32 and $len != 40) 回答3: <?php $name = mysql_real_escape_string($_POST['dgt']); $len = strlen($name); if ($len != 32

[kmp,不要过多调用strlen!!!] Codeforces 1200E Compress Words

匿名 (未验证) 提交于 2019-12-02 23:55:01
题目: http://codeforces.com/contest/1200/problem/E Compress Words time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output n sample" and " please" into " samplease". Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends. Input n 1 ≤ n ≤ 10 5 1≤n≤105), the number of the words in Amugae's sentence. n A', ' B', ..., ' Z', ' a', ' b', ..., ' z', ' 0', ' 1', ..., ' 10 6 106. Output In the

strlen和sizeof

一个人想着一个人 提交于 2019-12-02 23:51:49
char sArr[] = "ILOVEC"; /*用strlen()求长度*/ printf("sArr的长度=%d\n", strlen(sArr)); //很显然,上面示例代码的运行结果为 6(因为不包括结束字符 null)。 这里需要特别注意的是,函数 strlen 返回的是一个类型为 size_t 的值 //关键字 sizeof 是一个单目运算符,而不是一个函数。与函数 strlen 不同, 它的参数可以是数组、指针、类型、对象、函数等,如下面的示例代码所示: char sArr[] = "ILOVEC"; /*用sizeof求长度*/ printf("sArr的长度=%d\n", sizeof(sArr)); 模拟strlen(s) #include<stdio.h> int fun(char s[]); int fun(char s[]) { int i=0; while(s[i]) i++; return i; } int main(void) { int x; char p[81]="china"; x=fun(p); printf("%d",x); } 来源: https://www.cnblogs.com/kuugaxxx/p/11768085.html

关于批量下载ftp服务器的文件的方法

匿名 (未验证) 提交于 2019-12-02 23:41:02
前言:批量下载网上有一堆,但是无奈都基本是对自己项目作用不大,研究了一下,分享和记录 1.首先要知道这个是从html页面发起的所以必须要加入这段话才行 //之前尝试用ajax和layer弹层来实现发现都会产生错误因此必须要用这个方法才行,前端的方法 location.href = 你想要访问的.php网页; //后端的实现方法 <?php//这个class类是借鉴网友的,具体内部逻辑我也不太清晰,所以。。。。。。。class zipfile { var $datasec = array (); var $ctrl_dir = array (); var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; var $old_offset = 0; function unix2_dostime($unixtime = 0){ $timearray = ($unixtime == 0) ? getdate () : getdate($unixtime); if ($timearray ['year'] < 1980){ $timearray ['year'] = 1980; $timearray ['mon'] = 1; $timearray ['mday'] = 1; $timearray ['hours'] = 0;

学习随记:继续问号表达式的妙用……

匿名 (未验证) 提交于 2019-12-02 23:34:01
版权声明:知识内容为原创思考,转载请注明:转自 https://blog.csdn.net/SmartLoveyu/article/details/90338950 加深理解 问号表达式是将原本几行的if-else选择语句写在了一行,所以既然它能存在,一定不是只能做个选择罢了。所以尝试探索直接加上赋值会怎么样? 比如: int lenA = strlen(A); int lenB = strlen(B); int lenMax = lenA > lenB ? lenA : lenB; 这就是直接把赋值和判断结合在一起了,简洁明了。 文章来源: https://blog.csdn.net/SmartLoveyu/article/details/90338950