摘要:
逐個字符比較,直到遇到不同的,或者到了結尾。當s1<s2時,返回值<0 ; 當s1=s2時,返回值=0 ; 當s1>s2時,返回值>0#include<iostream>#include<cstring>using namespace std;int main(){ char *s1="China",*s2="Yinshiyong", *s3="China"; int x1, x2; x1 = strcmp(s1, s2); x2 = strcmp(s1, s3); cout<&l
閱讀全文
摘要:
函數名: strstr功 能: 在串str1中查找指定字符串str2, 返回值是一個指針。 找到了,就返回的是當前位置; 沒有找到,就返回空指針。用 法: char *strstr(char *str1, char *str2);#include<iostream>#include<cstring>using namespace std;int main(){ char *str1 = "Borland international add", *str2 = "nation", *ptr; ptr = strstr(str1, s
閱讀全文
摘要:
函數名: strspn功 能: 在串中查找兩個字符串不相同的起始位置用 法: int strspn(char *str1, char *str2);#include<iostream>#include<cstring>using namespace std;int main(){ char *string1 = "1234567890"; char *string2 = "1234DC8"; int length; length = strspn(string1, string2); cout<<"chara
閱讀全文
摘要:
函數名: strrev功 能: 串倒轉用 法: char *strrev(char *str);#include<iostream>#include<cstring>using namespace std;int main(){ ///forward最好是數組,否則出錯。 char forward[7] = "string"; cout<<"Before strrev():"<<forward<<endl; strrev(forward); cout<<"After str
閱讀全文
摘要:
函數名: strpbrk功 能: 在串中查找第一個在給定串中出現的字符用 法: char *strpbrk(char *str1, char *str2);#include<iostream>#include<cstring>using namespace std;int main(){ char *string1 = "abcdefghijklmnopqrstuvwxyz"; char *string2 = "omn"; char *ptr; ptr = strpbrk(string1, string2); if(ptr) co
閱讀全文
摘要:
函數名: stricmp功 能: 以不區分大小寫方式比較兩個串用 法: int stricmp(char *str1, char *str2);stricmp = stricmp#include<iostream>#include<cstring>using namespace std;int main(){ char buf2[5] ="Abbb", *buf1 = "cBBB" ; int ptr; ptr = stricmp(buf2, buf1); if(ptr>0) cout<<"buffer
閱讀全文
摘要:
///strncpy///原型:extern char *strncpy(char *dest, char *src, int n);///功能:把src所指由NULL結束的字符串的前n個字節復制到dest所指的數組中,取代dest/// 中最前面的n個字符。///說明:如果src的前n個字節不含NULL字符,則結果不會以NULL字符結束。/// 如果src的長度小于n個字節,則以NULL填充dest直到復制完n個字節。/// src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字符串。/// 返回指向dest的指針。有點小問題的代碼:#include<iost
閱讀全文
摘要:
///strncat///原型:extern char *strncat(char *dest,char *src,int n);///功能:把src所指字符串的前n個字符添加到dest結尾處(覆蓋dest結尾處的'\0')并添加'\0'。///說明:src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字符串。/// 返回指向dest的指針。#include<iostream>#include<cstring>using namespace std;int main(){ char dest[20] = &quo
閱讀全文
摘要:
///strcat///原型:extern char *strcat(char *dest,char *src)///功能:把src所指字符串添加到dest結尾處(覆蓋dest結尾處的'\0')并添加'\0'///說明:src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字符串。/// 返回指向dest的指針#include<iostream>#include<cstring>using namespace std;int main(){ char dest[20] = "Golden Global V
閱讀全文
摘要:
///strcpy///原型:extern char *strcpy(char *dest,char *src);///功能:把src所指由NULL結束的字符串復制到dest所指的數組中。///說明:src和dest所指內存區域不可以重疊且dest必須有足夠的空間來容納src的字符串。/// 返回指向dest的指針。#include<iostream>#include<cstring>using namespace std;int main(){ char *src = "Golden Global View"; char dest[20] ; //
閱讀全文
摘要:
#include <iostream>using namespace std;int a[50001];int qs(int s, int e){ int x = a[s], l = s, r = e; if(l >= r) return 0; while (l < r) { while(l<r && a[r]>=x) //從右向左掃描 r--; a[l] = a[r]; while(l<r && a[l]<=x) //從左向右掃描 l++; a[r] = ...
閱讀全文