• NOJ---1408----map的运用


            好吧  最近应该剁手了  停不下撸的节奏

                  我们还是先来看下这题吧

            touch me

    题目大意:

      就是给你一串字符串 你要找出其中符合的2个字符构成的字符串str 条件呢是  str[0]是辅音字母  str[1]是元音字母 -- aeiou--而且都是小写的

    其实 这应该算种方法  当你需要统计字符串个数时候 map真的是个好东西  而且stl里的容器 使用起来不负责  理解它的内存  很难

     有本叫做 《STL源码剖析》的似乎 很经典   以后在看吧

    这题 我做的时候 tle了好多次  cin cout看来在oj测试里 还是太慢了

    当我后来将 它改成scanf printf 后 还是 tle  最后 发现 string的构造函数 执行起来 也是效率不高的

    string(ch,pos,num)---ch即一个字符串的指针 pos 你要引用的位置 num个数  这就是我当时做题的时候 将找到的2个字符的字符串 存储到sring的方法 然后tle了

    然后 这边 介绍个更好的方法  string str = ""  这就相当于是个重置    你要是 以前里面有很多元素 如"abcd" 那么 这样就相当于清空了

    今天 一做 感觉 有时候 string 的一些函数 还是不错的 要是 效率可以再高点的话,,

    at last    let us see demo

     1 #include <iostream>
     2 #include <map>
     3 #include <string>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 const int size = 66666;
     8 char str[size];
     9 bool judge( char ch )
    10 {
    11     return ( ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' );
    12 }
    13 map<string,int>mp;
    14 int main()
    15 {
    16     int len;
    17     int i;
    18     while( ~scanf("%s",str) )
    19     {
    20         mp.clear();
    21         len = strlen(str);
    22         i = 0;
    23         string ch;
    24         while( i<len-1 )
    25         {
    26             if( !judge( str[i] ) && judge( str[i+1] ) )
    27             {
    28                 ch = "";
    29                 ch+=str[i];
    30                 ch+=str[i+1];
    31                 mp[ch]++;
    32                 i+=2;
    33             }
    34             else
    35             {
    36                 i++;
    37             }
    38         }
    39         map<string,int>::iterator it;
    40         for( it = mp.begin() ; it!=mp.end() ; it++ )
    41         {
    42             printf( "%s %d
    ",(it->first).c_str(),it->second );
    43         }
    44     }
    45     return 0;
    46 }
    View Code

    应该 今晚还会去做一题  质量不高啊.....

    just follow your heart
  • 相关阅读:
    Python的容器类型的遍历汇总
    python学习0313作业
    Python的字符编码
    hadoop-sqoop学习笔记
    eclipse Git & maven 安装
    使用mongoperf评估磁盘随机IO性能
    限制mongodb内存占用过高方法
    rabbitmq集群安装
    Perfmon
    mongodb所在目录空间不足解决方法
  • 原文地址:https://www.cnblogs.com/radical/p/3760212.html
Copyright © 2020-2023  润新知