Auto commit
This commit is contained in:
parent
0f66c6b6d8
commit
12172b99ca
@ -566,6 +566,35 @@ programming
|
||||
输出样例:index=7
|
||||
```
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(){
|
||||
int n, i, j;
|
||||
scanf("%d", &n);
|
||||
|
||||
char str[n][80];
|
||||
char temp[80];
|
||||
|
||||
for(i=0;i<n;i++){
|
||||
scanf("%s", *(str+i));
|
||||
}
|
||||
|
||||
for(i=0;i<n-1;i++){
|
||||
for(j=0;j<n-1-i;j++){
|
||||
if(strcmp(*(str+j), *(str+j+1)) == 1){
|
||||
strcpy(temp, *(str+j));
|
||||
strcpy(*(str+j), *(str+j+1));
|
||||
strcpy(*(str+j+1), temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i=0;i<n;i++){
|
||||
printf("%s\n", *(str+i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 15 字符串插入
|
||||
@ -640,6 +777,39 @@ ee
|
||||
输出样例:aeebc
|
||||
```
|
||||
|
||||
```c
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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<strlen(str2);i++){
|
||||
p = str1+strlen(str1);
|
||||
while(p>=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 <stdio.h>
|
||||
#include <string.h>
|
||||
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;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
## 进制转换
|
||||
|
Loading…
x
Reference in New Issue
Block a user