iterator排序STL Map hdu1004,1075,1263

新手发帖,很多方面都是刚入门,有错误的地方请大家见谅,欢迎批评指正

    map 的应用  注意first 为key值  second 是value值

    然后就是在杭电上头文件对于map的map<string,int >::iterator i;的操纵。应用#include<cstring>会编译错误。。<string>则不会

    对于hdu1263,由于map<string,int>存储是按KEY值的字母顺序排序,所以这里免去了排序的步调。

    STL很强大!

    hdu1004:

#include<iostream>
#include<string>
#include<map>
using namespace std;
map<string,int>M;
map<string,int>::iterator p,q;
int n;
int main()
{
    string str;
    while(scanf("%d",&n),n)
    {
       M.clear(); //清空
       while(n--)
       {
          cin>>str;
          if(M[str]==0) //插入
            M[str]=1;
          else 
              M[str]++;
       }
       int k=-1;
       for(p=M.begin();p!=M.end();p++)   //查找
       {
         if((p->second)>k)
         {
            k=p->second;
            q=p;
         }
       }
      cout<<q->first<<endl; 
    }
    return 0;
}

    
 然后是hdu1075

#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include<string>
#include<map>
using namespace std;
map<string,string> m;
map<string,string>::iterator it;
char c[3020];
int main()
{
    char s[22],t[22],tmp[22];
    scanf("%s",s);
    while(scanf("%s",s)!=EOF)
    {
        if(!strcmp(s,"END"))
            break;
        scanf("%s",t);
        m[t]=s;
    }
    scanf("%s",s);
    getchar();
    while(gets(c))
    {
        if(!strcmp(c,"END"))
            break;
        int len=strlen(c);
        int j=0;
        for(int i=0;i<len;i++)
        {
            if(c[i]>='a'&&c[i]<='z')
            {
                tmp[j]=c[i];
                j++;
            }
            else
            {
                tmp[j]='\0';
                it=m.find(tmp);
                if(it!=m.end())
                {
                    char ww[22];
                    //ww=it->second;
                    cout<<it->second;
                    //printf("%s",it->second);
                }
                else
                {
                    printf("%s",tmp);
                }
                printf("%c",c[i]);
                j=0;
            }
        }
        printf("\n");
    }
    return 0;
}
    每日一道理
翻开早已发黄的页张,试着寻找过去所留下的点点滴滴的足迹。多年前的好友似乎现在看来已变得陌生,匆忙之间,让这维持了多年的友谊变淡,找不出什么亲切感,只是偶尔遇上,淡淡地微笑,如今也只能在这发黄的页张中找寻过去的那些让人难忘的,至少我可以握住这仅剩下一段的“丝线头”……

    
最后hdu1263

#include<iostream>
#include<string>
#include<cstdio>
#include<map>
using namespace std;

int main()
{
    map<string,map<string,int> > a;
    map<string,int> b;
    map<string,map<string,int> >::iterator i;
    map<string,int>::iterator j;
    int T,m,tmp;string s,tb;
    cin>>T;
    while(T--)
    {
        a.clear();
        b.clear();
        cin>>m;
        while(m--)
        {
            cin>>s>>tb>>tmp;
            a[tb][s]+=tmp;
        }
        for(i=a.begin();i!=a.end();i++)
        {
            cout<<i->first<<endl;
            b=i->second;
            for(j=b.begin();j!=b.end();j++)
            {
                cout<<"   |----"<<j->first<<"("<<j->second<<")"<<endl;
            }
        }
        if(T!=0)
            printf("\n");
    }
}

    
 

文章结束给大家分享下程序员的一些笑话语录: 那是习惯决定的,一直保持一个习惯是不好的!IE6的用户不习惯多标签,但是最终肯定还是得转到多标签的浏览器。历史(软件UI)的进步(改善)不是以个人意志(习惯)为转移的!

--------------------------------- 原创文章 By
iterator和排序
---------------------------------

原文地址:https://www.cnblogs.com/xinyuyuanm/p/3105123.html