hdu 1860(字符串处理)

/*
  Author: Try_86 
  Date: 11/04/12 18:28
  Description: 字符串处理 
*/

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

char pat[6], str[81];
struct node {
    char c;
    int num;
}s[5];

void solve() {
    int lenP = strlen(pat);
    int lenS = strlen(str);
    for (int i=0; i<5; ++i) s[i].num = 0;
    for (int i=0; i<lenP; ++i) {
        for (int j=0; j<lenS; ++j) {
            if (pat[i] == str[j]) ++s[i].num, s[i].c = pat[i];
        }
    } 
    for (int i=0; i<lenP; ++i) printf ("%c %d\n", s[i].c, s[i].num);
}

int main() {
    while (gets(pat), pat[0]!='#') {
        gets(str);
        solve();
    }
    return 0;
}

 

posted on 2012-04-11 18:30  Try86  阅读(219)  评论(0)    收藏  举报