zoukankan      html  css  js  c++  java
  • STL之map UVa156

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <map>
     7 
     8 using namespace std;
     9 
    10 map<string,int> arr;
    11 vector<string> word;
    12 
    13 string change(string str)
    14 {
    15     string ans=str;
    16     for(int i=0;i<str.length();i++)
    17     {
    18         ans[i]=tolower(ans[i]);
    19     }
    20     sort(ans.begin(),ans.end());
    21     return ans;
    22 }
    23 
    24 int main()
    25 {
    26     string str,str1;
    27     while(cin>>str)
    28     {
    29         if(str[0]=='#')
    30             break;
    31         str1=change(str);
    32         word.push_back(str);
    33         if(!arr.count(str1))
    34             arr[str1]=0;
    35         arr[str1]++;
    36     }
    37     vector<string> ans;
    38     for(int i=0;i<word.size();i++)
    39     {
    40         if(arr[change(word[i])]==1)
    41            ans.push_back(word[i]);
    42     }
    43     sort(ans.begin(),ans.end());
    44     for(int i=0;i<ans.size();i++)
    45         cout<<ans[i]<<endl;
    46     return 0;
    47 }
    View Code

    map

    map类似于一个高级数组,下表类型可自行定义,类似于定义一个映射关系,也称“关联数组”

    可用函数

    count;  //看是否有这个下表,有,则返回1,没有则返回0

    find(n);  //看是否有n这个下标,如果没有,则返回值等于map.end();

    multimap

    multimap与map的区别在于第一个元素是否可重复

    对于multimap来说,find(n)会返回下标为n的第一个元素的指针

  • 相关阅读:
    C语言面试题——寻找错误
    C语言的声明解释的在线工具——cdecl
    C语言面试题——指针运算
    const 指针与指向const的指针
    C语言复杂声明解释
    poj1248
    poj1750
    poj1484
    poj1853
    poj1575
  • 原文地址:https://www.cnblogs.com/wsruning/p/4699680.html
Copyright © 2011-2022 走看看