字符串
字符串是一种数据结构类型,相应的,包括最基础的如string标准库中的一些字符串比较、拷贝、复制、子串查找、倒置等常规操作便应运而生。
更复杂一些的, 还有如字典树、字符串哈希、KMP算法、前缀/后缀问题、ASC自动机、后缀树、回文树、Manacher等拓展的高级算法都在此分类下。
-
有以下程序#include <stdio.h> #include <string.h> main() { char p[20]= {'a','b','c','d'}, q[]="abc", r[]="abcde"; strcat(p,r); strcpy(p+strlen(q),q); printf("%d\n",strlen(p)); }程序运行后的输出结果是()。
-
有以下程序:#include <stdio.h> #include <string.h> main() { char str[][20]={"One*World","One*Dream!"}, *p=str[1]; printf("%d,",strlen(p)); printf("%s\n",p); }程序运行后的输出结果是()。
-
有以下程序(程序中库函数islower(ch)用以判断ch中的字符是否为小写字母):#include <stdio.h> #include <ctype.h> void fun(char *p) { int i=0; while(p[i]) { if(p[i]==' '&&islower(p[i-1]))p[i-1]=p[i-1]-'a'+'A'; i++; } } main() { char s1[100]="ab cd EFG!"; fun(s1); printf("%s\n",s1); }程序运行后的输出结果是( )。
-
有以下程序(strcat函数用以连接两个字符串):#include <stdio.h> #include <string.h> main() { char a[20]="ABCD\0EFG\0", b[]="IJK"; strcat(a,b); printf("%s\n",a); }程序运行后的输出结果是()。
-
有以下程序:#include <stdio.h> #include <string.h> main() { char a[5][10]= {"china", "beijing", "you", "tiananmen", "welcome"}; int i,j; char t[10]; for(i=0;i<4;i++) for(j=i+1;j<5;j++) if(strcmp(a[i],a[j])>0) { strcpy(t,a[i]); strcpy(a[i],a[j]); strcpy(a[j],t); } puts(a[3]); }程序运行后的输出结果是()。
-
有以下程序:#include <stdio.h> #include <string.h> main() { int i; char a[]="How are you!"; for(i=0;a[i];i++) { if(a[i]==' ') { strcpy(a,&a[i+1]); i=0; } } printf("%s\n",a); }程序的运行结果是()。
-
有以下函数:int fun(char *s,char *t) { while((*s)&&(*t)&&(*t++==*s++)); return (*s-*t); }函数的功能是()。
-
下列函数的功能是()。fun(char * a,char * b) { while((*b= *a)!='\0') { a++; b++; } }
-
有以下函数:void fun(char*p,char*q) { while((*p++=*q++)!='\0'); }该函数的功能是()。
-
有以下函数int fun(char *s) { char *t=s; while(*t++); return(t-s); }该函数的功能是()。
-
有以下函数int aaa(char *s) { char *t=s; while(*t++); t--; return (t-s); }以下关于aaa函数功能叙述正确的是()。
-
有以下函数:int fun(char *ps) { char *p; p=ps; if(*ps==NULL)return 0; while(*++p); return(p-ps); }该函数的功能是()。
-
有以下函数:int fun(char *x,char *y) { int n=0; while((*x==*y)&&*x!='\0') { x++; y++: n++; } }函数的功能是()。
-
有以下程序:#include<stdio.h> #include<string.h> main() { char w[20],a[5][10]={"abcdef","ghijkl","mnopq","rstuv","wxyz."}; int i; for(i=0;i<5;i++)w[i]=a[i][strlen(a[i])-1]; w[5]='\0'; puts(w); }程序的运行结果是()。
-
有以下程序:#include <stdio.h> #include <string.h> main() { char s[]="Beijing"; printf("%d\n",strlen(strcpy(s,"China"))); }程序运行后的输出结果是()。
-
有以下程序:#include <stdio.h> #include <string.h> char *a="you"; char *b="Welcome you to Beijing!"; main() { char *p; p=b; while(*p != *a)p++; p+=strlen(a)+1; printf("%s\n",p); }程序运行后的输出结果是()。
-
有以下程序(其中的strstr()函数头部格式为:char *strstr(char*p1,char *p2)确定p2字符串是否在p1中出现,并返回p2第一次出现的字符串首地址):#include <stdio.h> #include <string.h> char *a="you"; char *b="Welcome you to Beijing!"; main() { char *p; p=strstr(b,a)+strlen(a)+1; printf("%s\n",p); }程序的运行结果是()。
-
有以下程序:#include <stdio.h> #include <string.h> main() { char a[20]="ab",b[20]="cdef"; int k=0; strcat(a,b); while(a[k]!='\0') { b[k]=a[k]; k++; } puts(b); }程序的运行结果是()。
-
有以下程序(strcpy为字符串复制函数,strcat为字符串连接函数):#include <stdio.h> #include <string.h> main() { char a[10] = "abc",b[10] = "012",c[10] = "xyz"; strcpy(a+1,b+2); puts(strcat(a,c+1)); }程序运行后的输出结果是()。
-
有以下程序#include <stdio.h> main() { char *p1 = 0; int *p2 = 0; float *p3 = 0; printf("%d,%d,%d\n", sizeof(p1), sizeof(p2), sizeof(p3)); }程序运行后的输出结果是()。