生活随笔
收集整理的這篇文章主要介紹了
【PAT乙级】1065 单身狗 (25 分)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目地址
#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std
;
map
<string
,string
>mp
;
map
<string
,bool>hush
;
string s
[50005];
vector
<string
> ve
;
int main(void)
{int n
; cin
>>n
;for(int i
=0;i
<n
;i
++){string a
,b
; cin
>>a
>>b
;mp
[a
]=b
,mp
[b
]=a
;}int m
; cin
>>m
;for(int i
=0;i
<m
;i
++) cin
>>s
[i
],hush
[s
[i
]]=true;for(int i
=0;i
<m
;i
++){if(hush
[mp
[s
[i
]]]) continue;ve
.push_back(s
[i
]);}sort(ve
.begin(),ve
.end());cout
<<ve
.size()<<endl
;for(int i
=0;i
<ve
.size();i
++){cout
<<ve
[i
];if(i
+1!=ve
.size()) cout
<<" ";}return 0;
}
#include<bits/stdc++.h>
using namespace std
;
map
<string
,string
>mp
;
map
<string
,int>st
;
vector
<string
>ans
;
string s
[50005];
int main(void)
{int n
; cin
>>n
;while(n
--){string a
,b
; cin
>>a
>>b
;mp
[a
]=b
,mp
[b
]=a
;}cin
>>n
;for(int i
=0;i
<n
;i
++) cin
>>s
[i
],st
[s
[i
]]++;for(int i
=0;i
<n
;i
++) if(!st
[mp
[s
[i
]]]) ans
.push_back(s
[i
]);cout
<<ans
.size()<<endl
;sort(ans
.begin(),ans
.end());for(int i
=0;i
<ans
.size();i
++){if(i
) cout
<<" ";cout
<<ans
[i
];}return 0;
}
總結(jié)
以上是生活随笔為你收集整理的【PAT乙级】1065 单身狗 (25 分)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。