zoukankan      html  css  js  c++  java
  • UVA10252 POJ2629 Common Permutation【字符串排序】

    问题链接:UVA10252 POJ2629 Common Permutation

    问题描述参见上文。两个小写字母构成的字符串a和b,求各自的置换的最长公共子串,按字母顺序输出。

    问题分析:(略)。

    程序说明:字符串类型变量的排序也是可以用函数sort()实现的。

    AC的C++语言程序如下:

    /* UVA10252 POJ2629 Common Permutation */
    
    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <cstring>
    #include <cstdio>
    
    using namespace std;
    
    int main()
    {
        string a, b;
        int lena, lenb;
    
        while(getline(cin, a) && getline(cin, b)) {
            // 计算字符串长度
            lena = a.size();
            lenb = b.size();
    
            // 字符串排序
            sort(a.begin(), a.end());
            sort(b.begin(), b.end());
    
            // 匹配求公共子串,输出结果
            for(int i=0, j=0; i<lena && j<lenb; ) {
                if(a[i] == b[j]) {
                    printf("%c", a[i]);
                    i++, j++;
                } else if(a[i] > b[j])
                    j++;
                else if(a[i] < b[j])
                    i++;
            }
            printf("
    ");
        }
    
        return 0;
    }


  • 相关阅读:
    php-文件系统
    php
    php
    php
    关于学习上面的感悟
    php
    Error: PostCSS plugin tailwindcss requires PostCSS 8.
    常用/不常用的HTTP状态码
    小程序云托管无需服务器部署PHP
    Docker-镜像操作
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564051.html
Copyright © 2011-2022 走看看