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
  • 相关阅读:
    Memcached 分布式缓存系统部署与调试
    nginx_笔记分享_php-fpm详解
    nginx_笔记分享_配置篇
    linux定时任务crond那些事!
    命令passwd报错因inode节点处理记录
    linux下定时任务
    linux内核堆栈
    c语言之单链表的创建及排序
    c语言常见的几种排序方法总结
    Tiny4412之外部中断
  • 原文地址:https://www.cnblogs.com/cyb123456/p/5834387.html
Copyright © 2011-2022 走看看