-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdissub.c
More file actions
42 lines (37 loc) · 686 Bytes
/
dissub.c
File metadata and controls
42 lines (37 loc) · 686 Bytes
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
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int dothing(char *, char *);
int main(void) {
FILE * f = fopen("input.txt", "r");
if (!f) {
printf("input.txt not found");
return 1;
}
char str1[10000];
char str2[100];
int i,j,k;
int n;
fscanf(f, "%d", &n);
for (i=0; i<n; i++) {
memset(str1, 0, 10000);
memset(str2, 0, 100);
fscanf(f, "%s", str1);
fscanf(f, "%s", str2);
printf("%d\n", dothing(str1, str2));
}
}
int dothing(char *str1, char *str2) {
int cnt = 0;
char *cur1 = str1;
char *cur2 = str2;
while (*cur1) {
if (*cur1 == *cur2) {
if (*(cur2+1))
cnt += dothing(cur1+1, cur2+1);
else cnt++;
}
cur1++;
}
return cnt;
}