• map, string 强大的STL


    Input
    Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
    Only one case.
     
    Output
    Your output should contain all the hat’s words, one per line, in alphabetical order.
     
    Sample Input
    a ahat hat hatword hziee word
     
    Sample Output
    ahat hatword
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <string>
    # include<cstring>
    using namespace std;
    #define MAX 51000
    map<string,int> m;
     string ch[MAX];
    int main()
    {
        char ch1[100],ch2[100];
        int i=0;
    
        while(cin>>ch[i])
        {
           m[ch[i++]]=1;
        }
        for(int j=0;j<i;j++)
        {
            for(int k=1;k<ch[j].size()-1;k++)
            {
                 string ch1(ch[j],0,k);     //表示把ch[j]中从下标0開始连续的k个字符串赋给ch1  
                 string ch2(ch[j],k,ch[j].size()-k);
                if(m[ch1]==1&&m[ch2]==1)
                {
                   cout<<ch[j]<<endl;
                    break;
                }
            }
        }
        return 0;
    }
    


     指针做:::;
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <algorithm>
    #include <string>
    # include<cstring>
    using namespace std;
    #define MAX 51000
     string ch[MAX];
    struct node{
        bool isword;
        node  *next[26];
        node()
        {
            isword=0;
            memset(next,NULL,sizeof(next));
        }
    };
    
    int insert(node *root,string s)
    {
        node *p=root;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'a';
           if(p->next[id]==NULL)  p->next[id]= new node();
               p= p->next[id];
        }
        p->isword=1;
    }
    int find(node *root,string s)
    {
        node *p =root;
        for(int i=0;i<s.size();i++)
        {
            int id=s[i]-'a';
            if(p->next[id]==NULL) return 0;
            p=p->next[id];
        }
        return p->isword;
    }
    int main()
    {
        char ch1[100],ch2[100];
        int i=0;
        node *root=new node();
        while(cin>>ch[i])
        {
            insert(root,ch[i]);
            i++;
        }
        for(int j=0;j<i;j++)
        {
            for(int k=1;k<ch[j].size()-1;k++)
            {
                 string ch1(ch[j],0,k);     //表示把ch[j]中从下标0開始连续的k个字符串赋给ch1
                 string ch2(ch[j],k,ch[j].size()-k);
                if(find(root,ch1)==1&&find(root,ch2)==1)
                {
                   cout<<ch[j]<<endl;
                    break;
                }
            }
        }
        return 0;
    }

    Codeforces Round #286 (Div. 2)    A. Mr. Kitayuta's Gift


    题意:  给你一个字符串,从字符a到字符z选一个字母插入不论什么位置使之成为回文串,不行输出“NA”。


    代码:    讨厌暴力有木有。

    。。


    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    
    bool  ispal(string str)
    {
        string hh=str;
        reverse(hh.begin(),hh.end());
        return hh==str ? 1:0;
    }
    int main()
    {
        string ss;
        while(cin>>ss)
        {
            bool flag=0;
            int len=ss.size();
            int h,i;
            for(i=0; i<=len; i++)
            {
    
                for(char j='a'; j<='z'; j++)
                {
                    string xa;
                    for(h=0; h<i; h++) xa+=ss[h];
                    xa+=j;
                    for(h=i; h<len; h++)  xa+=ss[h];
                    if(ispal(xa))
                    {
                        cout<<xa<<endl;
                        flag=1;
                        break;
                    }
                }
                if(flag) break;
            }
            if(!flag)  puts("NA");
    
        }
        return 0;
    }

    Codeforces Round #300  Cutting Banner
    题意:
             在一段不超过100的字符串中减掉一些子串之后能组成"CODEFORCES"则输出YES
    技巧:   对string进行取子串操作,S.substr(start,length)

    int main()
    {
    #ifndef  ONLINE_JUDGE
        freopen("in.cpp","r",stdin);
    #endif
        string s;
        string str1;
    
       while(cin>>s)
       {
           for(int i=0;i<s.size();i++)
           {
               for(int j=i+1;j<s.size();j++)
               {
                   str1=s.substr(0,i)+s.substr(j);
                    if(str1=="CODEFORCES")
                    {
                        printf("YES
    ");
                        return 0;
                    }
               }
           }
            puts("NO");
       }
        return 0;
    }*/


     

  • 相关阅读:
    H5(WebView)跳Native(UIView)
    URLManager官方解说
    iOS网络层框架之AFNetworking与 ASIHTTPRequest对比
    iOS 应用2.0版怎么做(转)
    善用iOS中webview(转)
    iOS实现在后台播放音乐
    CentOS 6.7安装Storm 0.9.7
    CentOS 6.7安装Storm 0.9.7
    CentOS 6.7安装Sqoop 1.4.6
    CentOS 6.7安装Sqoop 1.4.6
  • 原文地址:https://www.cnblogs.com/mthoutai/p/7133169.html
Copyright © 2020-2023  润新知