zoukankan      html  css  js  c++  java
  • POJ 1002

    思路:很坑爹的一道水题么,题目没说字符串有多长,一开始开的长度是30,一直RE。另外如果没有重复的输出的是No duplicates.,注意有句点。。。两种解法:map或者二叉搜索树中序遍历一次,维护一个cnt(记录次数)域。

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<map>
    using namespace std;
    char str[300];
    string temp;
    map<string, int>ss;
    int a[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5,
        6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9
    };
    void Switch(){
        char s[300];
        memset(s, 0, sizeof(str));
        temp.clear();
        int k = 0;
        int len = strlen(str);
        for(int i = 0;i < len;i ++){
            if(str[i] >= '0' && str[i] <= '9') s[k++] = str[i];
            if(str[i] >= 'A' && str[i] <= 'Z') s[k++] = a[str[i]-'A'] + '0';
            if(k == 3) s[k++] = '-'; 
        }
        temp = s;
    }
    int main(){
        int n;
        /* freopen("in.c", "r", stdin); */
        while(~scanf("%d", &n)){
            ss.clear();
            for(int i = 0; i < n;i ++){
                memset(str, 0, sizeof(str));
                scanf("%s", str);
                Switch();
                ss[temp]++;
            }
            int flag = 0;
            for(map<string, int>::iterator it = ss.begin(); it != ss.end(); ++it){
                if(it->second > 1){
                    flag = 1;
                    cout << it->first << " " << it->second << endl;
                }
            }
            if(flag == 0)
                printf("No duplicates.
    ");
        }
        return 0;
    }


    
    
    
    
  • 相关阅读:
    关于ShareSDK接入的各种问题,以及解决方案
    Cocos2d-x使用iOS游戏内付费IAP(C++篇)
    数论——终结素数判定
    poj 2528 线段树+离散化
    STL 优先队列
    poj 2777 线段树+延迟更新
    RMQ
    codeforces 拼手速题2
    codeforces 拼手速题1
    子矩阵 思维吧
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3933196.html
Copyright © 2011-2022 走看看