zoukankan      html  css  js  c++  java
  • Leetcode-888 两句话中的不常见单词

     1 class Solution
     2 {
     3     public:
     4         vector<string> uncommonFromSentences(string A, string B)
     5         {
     6             map<string,int> A_store,B_store;
     7             string A_words,B_words;
     8             for(int i = 0;i < A.size();i ++)
     9             {
    10                 if(A[i]!=' ')
    11                 {
    12                     A_words += A[i];
    13                 }
    14                 else
    15                 {
    16                     A_store[A_words] ++;
    17                     A_words.clear();
    18                 }
    19             }
    20             A_store[A_words] ++;
    21             A_words.clear();
    22             for(int i = 0;i < B.size();i ++)
    23             {
    24                 if(B[i]!=' ')
    25                 {
    26                     B_words += B[i];
    27                 }
    28                 else
    29                 {
    30                     B_store[B_words] ++;
    31                     B_words.clear();
    32                 }
    33             }
    34             B_store[B_words] ++;
    35             B_words.clear();
    36             vector<string> result;
    37             for(auto i = A_store.begin();i != A_store.end();i ++)
    38             {
    39                 string tmp = i->first;
    40                 int flag = 0;
    41                 for(auto j = B_store.begin();j != B_store.end();j ++)
    42                 {
    43                     if(j->first == tmp)
    44                         flag = 1;
    45                 }
    46                 if(flag==1)
    47                     continue;
    48                 else
    49                 {
    50                     if(i->second==1)
    51                         result.push_back(tmp);
    52                 }
    53             }
    54             for(auto i = B_store.begin();i != B_store.end();i ++)
    55             {
    56                 string tmp = i->first;
    57                 int flag = 0;
    58                 for(auto j = A_store.begin();j != A_store.end();j ++)
    59                 {
    60                     if(j->first == tmp)
    61                         flag = 1;
    62                 }
    63                 if(flag==1)
    64                     continue;
    65                 else
    66                 {
    67                     if(i->second==1)
    68                         result.push_back(tmp);
    69                 }
    70             }
    71             return result;
    72         }
    73 };
  • 相关阅读:
    ZOJ Problem Set
    数学之美:生活中的技术
    java泛型【收藏】
    "i=i++"在java等高级语言的解释
    poj1001
    ⑧javaWeb之在例子中学习(过滤器Filter)
    ZOJ Problem Set
    IT十年经典书籍
    ⑦JSP2.0的福利(标签文件)
    myeclipse-common 找不到
  • 原文地址:https://www.cnblogs.com/Asurudo/p/9477790.html
Copyright © 2011-2022 走看看