zoukankan      html  css  js  c++  java
  • uva 10252

    题意:給定兩個小寫的字串a與b,請印出皆出現在兩字串中的字母,出現的字母由a~z的順序印出,若同字母出現不只一次,請重複印出但不能超過任一字串中出現的次數。(from Ruby兔)

    很水,直接比较输出即可。

    代码:

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int maxn = 1001;
    
    int main() {
    	char a[maxn], b[maxn];
    	while (gets(a) != NULL && gets(b) != NULL) {
    		sort (a, a + strlen(a));
    		sort (b, b + strlen(b));
    //		printf("%s %s
    ", a, b);
    		for (int i = 0, j = 0; i < strlen(a) && j < strlen(b);) {
    			if (a[i] == b[j]) {
    				printf("%c", a[i]);
    				i++, j++;
    			}
    			else if (a[i] > b[j])
    				j++;
    			else
    				i++;
    		}//for
    		printf("
    ");
    	}//while
    	return 0;
    }





  • 相关阅读:
    Ethical Hacking
    Ethical Hacking
    Ethical Hacking
    National Treasures HDU
    Matrix HDU
    过山车 HDU
    Jimmy’s Assignment HDU
    Card Game Cheater HDU
    Uncle Tom's Inherited Land* HDU
    50 years, 50 colors HDU
  • 原文地址:https://www.cnblogs.com/java20130723/p/3212235.html
Copyright © 2011-2022 走看看