赋值了吗?
Time Limit: 1000MS |
Memory Limit: 65535KB |
Submissions: 161 |
Accepted: 43 |
Sample Input
3
1
a=a
2
b=c
c=d
4
b=a
c=d
d=b
e=f
Sample Output
a
none
a b d
1 #include <iostream>
2 #include <string>
3 #include <cstring>
4 #include <map>
5 using namespace std;
6
7 int main()
8 {
9 int i,j,k,T;
10 map <char,bool > mm;
11 char str[5]={'\0'};
12 cin>>T;
13 while(T--)
14 {
15 int num;
16 cin>>num;
17 //mm.clear();
18 mm.erase(mm.begin(),mm.end());
19 memset(str,0,sizeof(str));
20 mm['a'] = 1;
21 bool flag = 0;
22 for(i=1;i<=num;i++)
23 {
24 cin>>str;
25 if(str[2] == 'a')
26 flag = true;
27 //if(mm[str[2]]==1)// 用这个不能判断一个数是否存在
28 if(mm.count(str[2])==1)//count返回的是key的个数
29 //mm[str[0]] == 1;
30 mm.insert(pair<char,bool>(str[0],true));
31 }
32 if(flag==0)//flag这个变量很必须,不能用mm.size()==0
33 {
34 cout<<"none"<<endl;
35 }
36 else
37 {
38 map<char ,bool >::iterator ptr = mm.begin();
39 cout<<ptr->first;
40 ptr++;
41 for(;ptr!=mm.end();ptr++)
42 cout<<" "<<ptr->first;
43 cout<<endl;
44 }
45 cin>>unitbuf;
46 }
47 return 0;
48 }
49
50
51