这个程序接受输入的字符串数量,然后是实际的字符串。输出应该是所有字符串的公共字符数。
约束是:
- 字符串数 <= 100
- 字符串长度 <= 100
例如..
输入:
3 abc bcd cde
输出:
1
因为只有c对所有字符串都是通用的。
当与小输入一起使用时,它可以提供正确的输出。
它给出了 58 而不是 19 的错误输出。
这是我的代码:
#include<stdio.h>
#include<string.h>
void main(){
int n,i,j,count=0;
char s[100][100];
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s",s[i]);
}
int t;
int l = strlen(s[0]);
for(i=0;i<l;i++){
t=0;
for(j=1;j<n;j++){
if(strchr(s[j],s[0][i])!='\0'){
t++;
}
}
if(t==n-1)
count++;
}
printf("%d",count);
}