set:
集合a,b加起来,去重
hdu 1406
#include <iostream>
#include<cstdio>
#include<set>
using namespace std;
int main(int argc, char** argv) {
set<int> s;
set<int>:: iterator cp;
int a,b,n;
while(scanf("%d%d",&a,&b)!=EOF){
s.clear();
int Max=0;
for(int i=0;i<a+b;i++){
scanf("%d",&n);
Max=(n>Max)?n:Max;
s.insert(n);
}
for(cp=s.begin();cp!=s.end();cp++){
if(*cp!=Max)
printf("%d ",*cp);
else
printf("%d\n",*cp);
}
}
return 0;
}
map的用法
hdu 4802
#include <iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
int main(int argc, char** argv) {
int n,all,a;
double gpa;
char str[10];
int i,j;
map<string,double> mp;
mp["A"]=4;
mp["A-"]=3.7;
mp["B+"]=3.3;
mp["B"]=3;
mp["B-"]=2.7;
mp["C+"]=2.3;
mp["C"]=2;
mp["C-"]=1.7;
mp["D"]=1.3;
mp["D-"]=1;
mp["F"]=0;
while(scanf("%d",&n)!=EOF){
gpa=0;
all=0;
while(n--){
scanf("%d%s",&a,str);
if(mp.find(str)!=mp.end())
all+=a,gpa+=mp[str]*a;
}
if(gpa!=0)
gpa/=all;
printf("%.2lf\n",gpa);
}
return 0;
}