zoukankan      html  css  js  c++  java
  • 字符串排序 codeforce53A

    //简单描述对字符串的排序

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    string str;//字符串和字符串数组
    string a[1000];
    int main()
    {
      int n,j;
      scanf("%d",&n);
      j=0;
      for(int i=0;i<n;i++)
      {
        cin>>str;
        a[++j]=str;
      }
      sort(a+1,a+j+1);//begin---end+1
      for(int i=1;i<=j;i++)
      cout<<a[i]<<endl;
    }

    //codeforce 53A题意:输入一个字符串s,输入n,n个字符串如果n个字符串中有以s为前缀的字符串,输出字典序最小的字符串

    //如果没有以s为前缀的字符串则输出s

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    string a[105],s,stmp;
    int main()
    {
      int n;
      cin>>s; cin>>n;
      int len=s.size(),id=0;
      for(int i=0;i<n;i++)
      {
        cin>>stmp;
        if(stmp.substr(0,len)==s)//substr函数返回截取的字符串
        {
          //获得字符串s中从第0位开始长度为len的字符串
          //默认时长度为从开始到尾
          a[++id]=stmp;
        }
      }
      sort(a+1,a+id+1);
      if(!id)
        cout<<s<<endl;
      else
        cout<<a[1]<<endl;
      return 0;
    }

  • 相关阅读:
    安卓学习12
    安卓学习11
    安卓学习10
    安卓学习9
    Python3之json&pickle模块
    Mysql之基础sql语句
    Django模型层之单表操作
    创建Django项目与应用的两个命令
    windows命令行切换目录
    Django视图层之请求对象(request)和响应对象(HttpResponse)
  • 原文地址:https://www.cnblogs.com/renwjing/p/7356138.html
Copyright © 2011-2022 走看看