1
2
3
4
| (19) *p (20) *p-48
(21) n/2 (22) min=max=i
(23) k++ (24) strcpy(&s1[i],s3) (25) strcat(s1,temp) (26) k
(27) h2==NULL (28) s->next (29) h2 (30) return h1 |
(19) *p (20) *p-48
(21) n/2 (22) min=max=i
(23) k++ (24) strcpy(&s1[i],s3) (25) strcat(s1,temp) (26) k
(27) h2==NULL (28) s->next (29) h2 (30) return h1
14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| #include <stdio.h>
void fun(char *t,int count[])
{
char *p=t;
while (*p!='\0') {
if(*p>='0' && *p<='9')
count[*p-'0']++;
p++;
}
}
int main()
{
char s[80]="1enterschar4543123564879ffgh";
int count[10]= {0},i;
fun(s,count);
for(i=0; i<10; i++)
if(count[i]) printf("%d:%d ",i,count[i]);
return 0;
} |
#include <stdio.h>
void fun(char *t,int count[])
{
char *p=t;
while (*p!='\0') {
if(*p>='0' && *p<='9')
count[*p-'0']++;
p++;
}
}
int main()
{
char s[80]="1enterschar4543123564879ffgh";
int count[10]= {0},i;
fun(s,count);
for(i=0; i<10; i++)
if(count[i]) printf("%d:%d ",i,count[i]);
return 0;
}
15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| #include <stdio.h>
#define N 7
void sort(int a[],int n)
{
int i,j,min,max,t;
for(i=0; i<n-1; i++) {
min = i;
max = n-i-1;
for(j=i+1; j<n-i; j++)
if(a[j]<a[min]) min=j;
else if(a[j]>a[max])max=j;
if(min!=i) {
t=a[min]; a[min]=a[i]; a[i]=t;
}
if(max!=n-i-1)
if(max==i) {
t=a[min]; a[min]=a[n-i-1]; a[n-i-1]=t;
} else {
t=a[max]; a[max]=a[n-i-1]; a[n-i-1]=t;
}
}
}
int main()
{
int a[N]= {8,4,9,3,2,1,5},i;
sort(a,N);
printf("sorted:\n");
for(i=0; i<N; i++)
printf("%d\t",a[i]);
printf("\n");
return 0;
} |
#include <stdio.h>
#define N 7
void sort(int a[],int n)
{
int i,j,min,max,t;
for(i=0; i<n-1; i++) {
min = i;
max = n-i-1;
for(j=i+1; j<n-i; j++)
if(a[j]<a[min]) min=j;
else if(a[j]>a[max])max=j;
if(min!=i) {
t=a[min]; a[min]=a[i]; a[i]=t;
}
if(max!=n-i-1)
if(max==i) {
t=a[min]; a[min]=a[n-i-1]; a[n-i-1]=t;
} else {
t=a[max]; a[max]=a[n-i-1]; a[n-i-1]=t;
}
}
}
int main()
{
int a[N]= {8,4,9,3,2,1,5},i;
sort(a,N);
printf("sorted:\n");
for(i=0; i<N; i++)
printf("%d\t",a[i]);
printf("\n");
return 0;
}
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| #include <stdio.h>
int find_replace(char s1[],char s2[],char s3[])
{
int i,j,k,t=0;
char temp[80];
if(s1[0]=='\0'||s2[0]=='\0')return t;
for(i=0; s1[i]!='\0'; i++) {
k=0;
j=i;
while(s1[j]==s2[k]&&s2[k]!='\0') {
j++;
k++;
}
if(s2[k]=='\0') {
strcpy(temp,&s1[j]);
strcpy(&s1[i], s3);
i=i+strlen(s3);
strcpy(&s1[i], temp);
t=1;
}
}
return t;
}
int main(int argc, char *argv[])
{
char line[80]="This is a test program and a test data.";
char substr1[10]="test",substr2[10]="actual";
int k;
k=find_replace(line,substr1,substr2);
if(k==1)
puts(line);
else
printf("not found\n");
return 0;
} |
#include <stdio.h>
int find_replace(char s1[],char s2[],char s3[])
{
int i,j,k,t=0;
char temp[80];
if(s1[0]=='\0'||s2[0]=='\0')return t;
for(i=0; s1[i]!='\0'; i++) {
k=0;
j=i;
while(s1[j]==s2[k]&&s2[k]!='\0') {
j++;
k++;
}
if(s2[k]=='\0') {
strcpy(temp,&s1[j]);
strcpy(&s1[i], s3);
i=i+strlen(s3);
strcpy(&s1[i], temp);
t=1;
}
}
return t;
}
int main(int argc, char *argv[])
{
char line[80]="This is a test program and a test data.";
char substr1[10]="test",substr2[10]="actual";
int k;
k=find_replace(line,substr1,substr2);
if(k==1)
puts(line);
else
printf("not found\n");
return 0;
}
17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| typedef struct node {
int data;
struct node *next;
} NODE;
NODE *sea_del(NODE *h1,NODE *h2)
{
NODE *p,*ph,*q,*s;
ph=NULL;
p=q=h1;
s=h2;
if(h1==NULL|| h2==NULL) return h1;
while(p!=NULL && s!=NULL)
{
while(q->data==s->data&&q&&s)
{
q=q->next;
s=s->next;
}
if(s!=NULL) /*失配时,h1起始结点后移,h2从首结点开始*/
{
ph=p;
p=q=p->next;
s=h2;
}
else
if(ph==NULL) h1=q;
else ph->next=q;
}
return h1 ;
} |
typedef struct node {
int data;
struct node *next;
} NODE;
NODE *sea_del(NODE *h1,NODE *h2)
{
NODE *p,*ph,*q,*s;
ph=NULL;
p=q=h1;
s=h2;
if(h1==NULL|| h2==NULL) return h1;
while(p!=NULL && s!=NULL)
{
while(q->data==s->data&&q&&s)
{
q=q->next;
s=s->next;
}
if(s!=NULL) /*失配时,h1起始结点后移,h2从首结点开始*/
{
ph=p;
p=q=p->next;
s=h2;
}
else
if(ph==NULL) h1=q;
else ph->next=q;
}
return h1 ;
}