当前位置:编程学习 > C/C++ >>

UVa 10785 - The Mad Numerologist

C++代码:
 
#include <iostream>  
#include <string>  
#include <algorithm>  
using namespace std;  
int main()  
{  
    string vowels="AAAAAAAAAAAAAAAAAAAAAUUUUUUUUUUUUUUUUUUUUUEEEEEEEEEEEEEEEEEEEEEOOOOOOOOOOOOOOOOOOOOOIIIIIIIIIIIIIIIIIIIII";  
    string consonants="JJJJJSSSSSBBBBBKKKKKTTTTTCCCCCLLLLLDDDDDMMMMMVVVVVNNNNNWWWWWFFFFFXXXXXGGGGGPPPPPYYYYYHHHHHQQQQQZZZZZRRRRR";  
    int n;  
    while (cin>>n)  
    {  
        for(int cas=1;cas<=n;++cas)  
        {  
            int m;  
            cin>>m;  
            string name,name1,name2;  
            int i,j;  
            i=j=0;  
            int num=0;  
            int size_vowels=vowels.size();  
            int size_consonants=consonants.size();  
            while(num<m)  
            {  
                name1+=vowels[i];  
                i=(i+1)%size_vowels;  
                ++num;  
                if(num>=m)break;  
                name2+=consonants[j];  
                j=(j+1)%size_consonants;  
                ++num;  
            }  
            sort(name1.begin(),name1.end());  
            sort(name2.begin(),name2.end());  
            i=j=0;  
            while(i<name1.size()&&j<name2.size())  
            {  
                name+=name1[i++];  
                name+=name2[j++];  
            }  
            if(i<name1.size())  
                name+=name1[i];  
            if(j<name2.size())  
                name+=name2[j];  
            cout<<"Case "<<cas<<": "<<name<<endl;  
        }  
    }  
    return 0;  
}  

 

 
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,