题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3150
2 4 Gypsy TomServo CrowTRobot Cambot 2 Manos Torgo Joel 101010 Gypsy tomservo Fugitive Alien Time of the Apes crowTrobot Cambot 2 R2D2 C3PO 1 Boba Fett c3Po R2D22 Jar Jar Binks Luke give in to the dark side
Test set 1: Gypsy is present TomServo is absent CrowTRobot is absent Cambot is present Test set 2: R2D2 is absent C3PO is absent
PS:
判断给出的表单是否在下面有出现!
代码如下:
#include <cstdio> #include <map> #include <cstring> #include <string> #include <algorithm> #include <iostream> using namespace std; map<string,int>mm; int main() { string name[117]; int t; int n; int cas = 0; scanf("%d",&t); while(t--) { scanf("%d",&n); mm.clear(); for(int i = 0; i < n; i++) { cin>>name[i]; } int m; scanf("%d",&m); char s[1000]; string ss=""; for(int i = 0; i < m; i++) { getchar(); gets(s); for(int j = 0; j < strlen(s); j++) { if(s[j]==' ') { mm[ss]++; ss=""; continue; } ss+=s[j]; } mm[ss]++; ss=""; } printf("Test set %d:\n",++cas); for(int i = 0 ; i < n; i++) { if(mm[name[i]]) { //printf("%s is present\n",name[i]); cout<<name[i]<<" is present"<<endl; } else { //printf("%s is absent\n",name[i]); cout<<name[i]<<" is absent"<<endl; } } printf("\n"); } return 0; }
HDU 3150 Robot Roll Call – Cambot…Servo…Gypsy…Croooow(map)
原文地址:http://blog.csdn.net/u012860063/article/details/39857573