zoukankan      html  css  js  c++  java
  • UVa156

    题意:

           输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排得到输入文本中的另外一个单词。在判断是否满足条件时,字母不区分大小写,但在输出时应该保留输入中的大小写,按字典序进行排列。

    分析:

           将输入的单词进行“标准化”,即将单词中的每个字母化为小写并按字典序重排单词,用一个字典来统计一个标准化的单词出现过多少次,输出的时候只输出在标准字典中出现一次的那些单词即可。

     1 #include <iostream>
     2 #include <string>
     3 #include <map>
     4 #include <vector>
     5 #include <algorithm>
     6 using namespace std;
     7 // 将单词进行标准化
     8 string repr(const string& s){
     9     string ans = s;
    10     for(int i = 0 ; i < ans.length() ; i++)
    11         ans[i] = tolower(ans[i]);
    12     sort(ans.begin(),ans.end());
    13     return ans;
    14 }
    15 vector<string> words;
    16 map<string,int> cnt;
    17 int main(){
    18     int n = 0;
    19     string s;
    20     while(cin >> s){
    21         if(s[0] == '#') break;
    22         words.push_back(s);
    23         string r = repr(s);
    24         if(!cnt.count(r)) cnt[r] = 0;
    25         cnt[r]++;
    26     }
    27     vector<string> ans;
    28     for(int i = 0 ; i < words.size() ; i++)
    29         if(cnt[repr(words[i])] == 1) ans.push_back(words[i]);
    30     sort(ans.begin(),ans.end());
    31     for(int i = 0 ; i < ans.size() ; i++)
    32         cout << ans[i] << endl;
    33     return 0;
    34 }
    View Code
  • 相关阅读:
    How Default Heap Of Process Grows
    希腊字母表
    Ubuntu第一次亲密接触
    Ubuntu中的挂载点(mount point)
    要一专多能
    First touch with JIT debugging
    小学一下环境变量
    安装VMware Tools
    [转]ReiserFS与ext3的比较
    [bbk4485]第二章Flashback Database 05
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5834387.html
Copyright © 2011-2022 走看看