栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3674 Search in the Wiki

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3674 Search in the Wiki

# include <iostream># include<stdio.h># include<string.h># include<stdlib.h># include<math.h># include<algorithm># include<map># include<vector>using namespace std;struct str{ char a[205][35]; int x;}s[105];char ch[105][35];int num[105];char str1[3505];map<string, int> mapp;struct str2{ char aa[35];}ss[205];bool cmp(str2 x1, str2 y1){ return strcmp(x1.aa, y1.aa) < 0;}int main(){ int n; while(~scanf("%d", &n)) { for(int i = 0; i < n; i ++) { scanf("%s", ch[i]); getchar(); gets(str1); int len = strlen(str1); char chch[35]; memset(chch, '', sizeof(chch)); int l = 0; for(int j = 0, k = 0; j <= len; j ++) { if(str1[j] != ' ' && str1[j] != '') chch[k ++] = str1[j]; else { strcpy(s[i].a[l ++], chch); memset(chch, '', sizeof(chch)); k = 0; } } s[i].x = l; } int m; scanf("%d", &m); getchar(); for(int i = 0; i < m; i ++) { mapp.clear(); gets(str1); int len = strlen(str1); char chch[35]; memset(chch, '', sizeof(chch)); int l = 0, count = 0, ii = 0; for(int j = 0; j <= len; j ++) { if(str1[j] != ' ' && str1[j] != '') chch[l ++] = str1[j]; else { count ++; for(int kk = 0; kk < n; kk ++) { if(strcmp(chch, ch[kk]) == 0) { num[ii ++] = kk; break; } } memset(chch, '', sizeof(chch)); l = 0; } } for(int i = 0; i < count; i ++) { for(int j = 0; j < s[num[i]].x; j ++) { mapp[s[num[i]].a[j]] ++; } } int k = 0; for(int i = 0; i < s[num[0]].x ; i ++) { if(mapp[s[num[0]].a[i]] == count) { strcpy(ss[k ++].aa,s[num[0]].a[i]); } } if(k == 0) printf("NOn"); else { sort(ss,ss + k, cmp); int f = 0; for(int i = 0; i < k; i ++) { if(f == 1) { printf(" "); } printf("%s", ss[i].aa); f = 1; } printf("n"); } } } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373492.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号