1 条题解
-
0
C :
#include<stdio.h> #include<string.h> #include<math.h> int main() { int n,i,t,flag=0,num=0,len,j,k,l; char s[100][105],s1[25],temp[25]; scanf("%d",&t); for(i=0;i<t;i++) { num=0; scanf("%d",&n); getchar(); gets(s1); for(j=0;j<n;j++) gets(s[j]); for(j=0;j<n;j++) { len=strlen(s[j]); k=0; for(l=0;l<=len;l++) { if(s[j][l]!=' '&& s[j][l]!='\0') temp[k++]=s[j][l]; else { temp[k]='\0'; if(strcmp(temp,s1)==0) num++; k=0; } } } if(num==0) printf("Do not find\n"); else printf("%d\n",num); } return 0; }
C++ :
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; char t[25]; char f[105]; bool judge(){ char word[105];int j = 0; int len = strlen(f); for (int i = 0; i <= len; i++){ if(isalpha(f[i])){ word[j++] = f[i]; } else{ word[j] = '\0'; if(strcmp(t,word) == 0){ return 1; } j = 0; } } return 0; } int main() { //freopen("zhaoweijie12.in", "r", stdin); //freopen("zhaoweijie12.out", "w", stdout); int tst,n,cnt; scanf("%d", &tst); for (int i = 1; i <= tst; i++){ cnt = 0; scanf("%d", &n);getchar(); gets(t); for (int j = 1; j <= n; j++){ gets(f); if(judge()){ cnt++; } } if(cnt == 0){ puts("Do not find"); } else{ printf("%d\n", cnt); } } return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { int T,N; String word,sentence; Scanner in = new Scanner(System.in); T = in.nextInt(); for(int i=0;i<T;i++){ int sum = 0; N = in.nextInt(); word = in.next(); in.nextLine(); for(int j=0;j<N;j++){ sentence = in.nextLine(); String[] str = sentence.split(" "); for(String s :str){ if(s.equals(word)){ sum++; break; } } } if(sum>0) System.out.println(sum); else System.out.println("Do not find"); } } }
- 1
信息
- ID
- 820
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者