diff --git a/最后一舞/C语言基础进阶合集版编程题.md b/最后一舞/C语言基础进阶合集版编程题.md index 78b555b..3805f99 100644 --- a/最后一舞/C语言基础进阶合集版编程题.md +++ b/最后一舞/C语言基础进阶合集版编程题.md @@ -566,6 +566,35 @@ programming 输出样例:index=7 ``` +```c +#include + +int main(){ + char target, *p; + char str[100]; + + char *index = NULL; + p = str; + scanf("%c", &target); + scanf("%s", str); + while(*p != '\0'){ + if(*p == target){ + index = p; + } + p++; + } + if(index != NULL){ + printf("index=%d\n", index-str); + }else{ + printf("Not Found\n"); + } + + + return 0; +} + +``` + ### 12 大小写转换 @@ -586,6 +615,37 @@ $%*& dC 32!Ba ``` +```c +#include + +int main(){ + char ch; + char str[100]; + char *p = str; + + while((ch=getchar())!= '#'){ + if(ch >= 'a' && ch <= 'z'){ + *p = ch-32; + }else if(ch >= 'A' && ch <= 'Z'){ + *p = ch+32; + }else{ + *p = ch; + } + p++; + } + while(p!= str){ + p--; + putchar(*p); + } + printf("\n"); + + + + return 0; +} + +``` + ### 13 字符串比较 @@ -602,6 +662,47 @@ love 输出样例:0 ``` +```c +#include + +int main(){ + char str1[100], str2[100]; + char *p, *q, flag; + + p = str1; + q = str2; + gets(str1); + gets(str2); + + while(*p != '\0' && *q != '\0'){ + if(*p > *q){ + flag = 1; + break; + }else if(*p < *q){ + flag = -1; + break; + } + p++; + q++; + } + if(*p == '\0' && *q == '\0'){ + flag = 0; + } + if(*p != '\0' && *q == '\0'){ + flag = 1; + } + if(*p == '\0' && *q != '\0'){ + flag = -1; + } + printf("%d\n", flag); + + + + return 0; +} + +``` + ### 14 字符串排序 @@ -623,6 +724,42 @@ abc b ``` +```c +#include +#include + +int main(){ + int n, i, j; + scanf("%d", &n); + + char str[n][80]; + char temp[80]; + + for(i=0;i +#include + +int main(){ + char str1[100], str2[100]; + int n, i; + char *p, *q; + scanf("%s %s", str1, str2); + scanf("%d", &n); + + for(i=0;i=str1+n+i-1){ + *(p+1) = *p; + p--; + } + } + p = str1+n-1; + q = str2; + while(*q != '\0'){ + *p = *q; + p++; + q++; + } + + printf("%s\n%s", str1, str2); + + return 0; +} + +``` + ### 16 字符串删除 @@ -656,6 +826,50 @@ dee 输出样例:abcdf ``` +```c +#include +#include +int main(){ + char str1[100], str2[100]; + int n; + char *p, *q; + scanf("%s", str1); + scanf("%s", str2); + p = str1; + while(*p != '\0'){ + q = str2; + while(*q == *p && *q != '\0'){ + p++; + q++; + } + if(*q == '\0'){ + q = p; + while(*q != '\0'){ + *(q-strlen(str2)) = *q; + q++; + } + *(q-strlen(str2))='\0'; + p-=strlen(str2); + } + if(*p == *str2){ + p--; + } + p++; + } + + + printf("%s\n", str1); + + + + + return 0; +} + +``` + + + --- ## 进制转换