map 的使用 注意first 为key值 second 是value值
然后就是在杭电上头文件对于map的map<string,int >::iterator i;的操作。使用#include会编译错误。。则不会
对于hdu1263,由于map<string,int>存储是按KEY值的字母顺序排序,所以这里免去了排序的步骤。
STL很强大!
hdu1004:
[cpp] view plain copy
#include
#include
#include
然后是hdu1075
[cpp] view plain copy
#include <stdlib.h>
#include
#include <stdio.h>
#include
#include
using namespace std;
map<string,string> m;
map<string,string>::iterator it;
char c[3020];
int main()
{
char s[22],t[22],tmp[22];
scanf("%s",s);
while(scanf("%s",s)!=EOF)
{
if(!strcmp(s,“END”))
break;
scanf("%s",t);
m[t]=s;
}
scanf("%s",s);
getchar();
while(gets©)
{
if(!strcmp(c,“END”))
break;
int len=strlen©;
int j=0;
for(int i=0;i<len;i++)
{
if(c[i]>=‘a’&&c[i]<=‘z’)
{
tmp[j]=c[i];
j++;
}
else
{
tmp[j]=’\0’;
it=m.find(tmp);
if(it!=m.end())
{
char ww[22];
//ww=it->second;
cout<second;
//printf("%s",it->second);
}
else
{
printf("%s",tmp);
}
printf("%c",c[i]);
j=0;
}
}
printf("\n");
}
return 0;
}
#include <stdlib.h>
#include
#include <stdio.h>
#include
#include
using namespace std;
map<string,string> m;
map<string,string>::iterator it;
char c[3020];
int main()
{
char s[22],t[22],tmp[22];
scanf("%s",s);
while(scanf("%s",s)!=EOF)
{
if(!strcmp(s,“END”))
break;
scanf("%s",t);
m[t]=s;
}
scanf("%s",s);
getchar();
while(gets©)
{
if(!strcmp(c,“END”))
break;
int len=strlen©;
int j=0;
for(int i=0;i<len;i++)
{
if(c[i]>=‘a’&&c[i]<=‘z’)
{
tmp[j]=c[i];
j++;
}
else
{
tmp[j]=’\0’;
it=m.find(tmp);
if(it!=m.end())
{
char ww[22];
//ww=it->second;
cout<second;
//printf("%s",it->second);
}
else
{
printf("%s",tmp);
}
printf("%c",c[i]);
j=0;
}
}
printf("\n");
}
return 0;
}
最后hdu1263
[cpp] view plain copy
#include
#include
#include
#include
using namespace std;
int main()
{
map<string,map<string,int> > a;
map<string,int> b;
map<string,map<string,int> >::iterator i;
map<string,int>::iterator j;
int T,m,tmp;string s,tb;
cin>>T;
while(T–)
{
a.clear();
b.clear();
cin>>m;
while(m–)
{
cin>>s>>tb>>tmp;
a[tb][s]+=tmp;
}
for(i=a.begin();i!=a.end();i++)
{
cout<first<<endl;
b=i->second;
for(j=b.begin();j!=b.end();j++)
{
cout<<" |----"<first<<"("<second<<")"<<endl;
}
}
if(T!=0)
printf("\n");
}
}
#include
#include
#include
#include
using namespace std;
int main()
{
map<string,map<string,int> > a;
map<string,int> b;
map<string,map<string,int> >::iterator i;
map<string,int>::iterator j;
int T,m,tmp;string s,tb;
cin>>T;
while(T–)
{
a.clear();
b.clear();
cin>>m;
while(m–)
{
cin>>s>>tb>>tmp;
a[tb][s]+=tmp;
}
for(i=a.begin();i!=a.end();i++)
{
cout<first<<endl;
b=i->second;
for(j=b.begin();j!=b.end();j++)
{
cout<<" |----"<first<<"("<second<<")"<<endl;
}
}
if(T!=0)
printf("\n");
}
}