map简单用法
2017-04-05 20:47
260 查看
在做很多题的时候发现map真的好用 但是我不会 我现在也只学了一点皮毛 怕以后会忘掉 现在赶紧记下来
需要标记的题用map可能会事半功倍,数字被标记可以用数组
但是字符就不行了
头文件#include<map>
//map<int,int>q;//第一个int是指q[]中的类型,第二个int指q[]=的类型,eg:q[1]=1;
//当然第一个int也可以是char
//q.clear();是清空map用的,主要在多组输入时要用
一般可用来做标记
比如cf的Face Detectionhttp://codeforces.com/problemset/problem/549/A
用map就很好写
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int n,m;
int sum=0;
char a[55][55];
scanf("%d%d",&n,&m);
map<char,int>q;
for(int i=0; i<n; i++)
{
scanf("%s",a[i]);
}
for(int i=0; i<n-1; i++)
{
for(int j=0; j<m-1; j++)
{
q.clear();//每次使用都清空
q[a[i][j]]=1;//每四个四个查看即2*2这种模式,每次查看4个
q[a[i+1][j]]=1;
q[a[i+1][j+1]]=1;
q[a[i][j+1]]=1;
if(q['f']&&q['a']&&q['c']&&q['e'])//如果这四个全是要求的字符就sum加一
sum++;
}
}
printf("%d\n",sum);
}
需要标记的题用map可能会事半功倍,数字被标记可以用数组
但是字符就不行了
头文件#include<map>
//map<int,int>q;//第一个int是指q[]中的类型,第二个int指q[]=的类型,eg:q[1]=1;
//当然第一个int也可以是char
//q.clear();是清空map用的,主要在多组输入时要用
一般可用来做标记
比如cf的Face Detectionhttp://codeforces.com/problemset/problem/549/A
用map就很好写
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int n,m;
int sum=0;
char a[55][55];
scanf("%d%d",&n,&m);
map<char,int>q;
for(int i=0; i<n; i++)
{
scanf("%s",a[i]);
}
for(int i=0; i<n-1; i++)
{
for(int j=0; j<m-1; j++)
{
q.clear();//每次使用都清空
q[a[i][j]]=1;//每四个四个查看即2*2这种模式,每次查看4个
q[a[i+1][j]]=1;
q[a[i+1][j+1]]=1;
q[a[i][j+1]]=1;
if(q['f']&&q['a']&&q['c']&&q['e'])//如果这四个全是要求的字符就sum加一
sum++;
}
}
printf("%d\n",sum);
}
相关文章推荐
- Map的简单用法入门
- map的简单用法,来自欧大神
- RxAndroid之Action,Func,map,flatmap的简单用法。
- map 与 set 简单用法
- HDU1004 Let the ballon raise(水题, 字符串的处理)(map简单用法)
- map 简单用法
- hdu 5233 Gunner II (map的简单用法)
- codeforces 499B Lecture(map与string简单用法)
- map的简单用法
- map的 简单用法
- uva 11991 Easy Problem from Rujia Liu?(数据结构:map的简单用法)
- java中Set,Map,Stack一些简单用法
- HDU1004 Let the Balloon Rise(map的简单用法)
- perl grep 和 map 简单用法
- Map.Entry<K,V> 的简单用法
- map的简单用法
- GO的MAP字典简单用法示例
- JAVA中MAP的四种类型区别和常见的简单用法
- code forces 4C Registration system (map 的简单用法)
- set和map的简单用法