当前位置:编程学习 > 网站相关 >>

nbut[1408] Dolly Song 大水题 辅音+元音 输出此类单词的个数

[1408] Dolly Song
时间限制: 1000 ms 内存限制: 65535 K
问题描述

Please listen to this song. Is it familiar?

You know, the lyrics is "ba la du la di li @&**(&#(!*@&#(*!@&#(*!@&#". Well it's just a joke.

We need you to caculate how many syllables in this song.

To simplify this problem, we just assume a consonant followed a vowel(AEIOU) called a

syllable. For examples, 'ba', 'la', 'du' and so on are syllables.

You should caculate out the count of each syllable.

输入
This problem contains several cases.
Each case is a line of string with only lowercase letters. (No longer than 65535)
输出
For each case, you should list all of the appeared syllables sorted by lexicographical and its times.

样例输入
baulaubilibiliuuuauaja
样例输出
ba 1
bi 2
ja 1
la 1
li 2
提示
无来源
XadillaX
题意 :输入一个字符串 看其中的  2个字符的单词 辅音+元音的   单词的个数
 
思路 map记录即可
 
[cpp]
#include<stdio.h>  
#include<map>  
#include<string>  
#include<string.h>  
#include<algorithm>  
#include<iostream>  
using namespace std; 
map<string,int>mp; 
map<string,int>::iterator it; 
char s[70000]; 
int is(char ch1,char ch2 ) 

       if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u') return 0; 
       if(ch2=='a'||ch2=='e'||ch2=='i'||ch2=='o'||ch2=='u') return 1; 
       return 0; 

int main() 

    int i; 
    string str; 
    while(scanf("%s",s)!=EOF) 
    { 
        mp.clear(); 
         int len=strlen(s); 
         for(i=0;i<len-1;i++) 
         { 
             str=""; 
                         str+=s[i]; 
              str+=s[i+1]; 
              if(is(s[i],s[i+1])) 
                  mp[str]++; 
         } 
         for(it=mp.begin();it!=mp.end();it++) 
         { 
             //cout<<it->first<<" "<<it->second<<endl;  
             printf("%s %d\n",it->first.c_str(),it->second); 
             //it->second=0;  
         } 
          
    } 
     return 0; 

#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
map<string,int>mp;
map<string,int>::iterator it;
char s[70000];
int is(char ch1,char ch2 )
{
       if(ch1=='a'||ch1=='e'||ch1=='i'||ch1=='o'||ch1=='u') return 0;
    if(ch2=='a'||ch2=='e'||ch2=='i'||ch2=='o'||ch2=='u') return 1;
    return 0;
}
int main()
{
 int i;
 string str;
 while(scanf("%s",s)!=EOF)
 {
  mp.clear();
         int len=strlen(s);
   for(i=0;i<len-1;i++)
   {
    str="";
                         str+=s[i];
     str+=s[i+1];
     if(is(s[i],s[i+1]))
      mp[str]++;
   }
   for(it=mp.begin();it!=mp.end();it++)
   {
    //cout<<it->first<<" "<<it->second<<endl;
    printf("%s %d\n",it->first.c_str(),it->second);
    //it->second=0;
   }
  
 }
     return 0;
}


 

补充:综合编程 , 其他综合 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,