UVA - 10785 The Mad Numerologist

简介:

题目链接

这个题又犯了省题不清的错误。导致不停 wa。唉。

题目意思是给你一个长度L,然后和一张表相应每一个大写字母的value值。你须要依照一定规则找出长度为L的序列。

注意  序列的value值要最小,而且须要按字典序排,就是按字典序排,一直没意识到,事实上在依据value值选出最小序列之后,还要分别排序,这样得出的才是字典序最小的序列。

知道这个就分别找出元音和辅音的序列然后排序就可以。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char ss[]="JSBKTCLDMVNWFXGPYHQZR";
char s[]="AUEOI";

int cmp(const void* a,const void* b)
{
    char* _a=(char*) a;
    char* _b=(char*) b;
    return *_a-*_b;
}
int main()
{
    freopen("a.txt","r",stdin);
    char s1[200],s2[200];
    int t,n,i,j=1;
    scanf("%d",&t);
    while(t--)
    {
        memset(s1,'\0',sizeof(s1));
        memset(s2,'\0',sizeof(s2));
        printf("Case %d: ",j++);
        scanf("%d",&n);
        int l1=0,l2=0;
        int x=0,y=0;
        int c1=0,c2=0;
        for(i=0;i<n/2;i++)
        {
            s1[l1++]=s[x];
            s2[l2++]=ss[y];
            c1++;c2++;
            if(c1==21)
            {
                c1=0;
                x++;
            }
            if(c2==5)
            {
                c2=0;
                y++;
            }
        }
        if(n/2) s1[l1++]=s[x];
        qsort(s1,l1,sizeof(char),cmp);
        qsort(s2,l2,sizeof(char),cmp);
        for(i=0;i<n/2;i++)
        {
            printf("%c%c",s1[i],s2[i]);
        }
        if(n/2) printf("%c",s1[n/2]);
        printf("\n");
    }
    return 0;
}





本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5320445.html,如需转载请自行联系原作者
相关文章
|
9月前
UVa1531 - Problem Bee
UVa1531 - Problem Bee
34 0
|
9月前
UVa11565 - Simple Equations
UVa11565 - Simple Equations
35 0
|
9月前
UVa389 - Basically Speaking
UVa389 - Basically Speaking
24 0
UVA10474 大理石在哪儿 Where is the Marble?
UVA10474 大理石在哪儿 Where is the Marble?
UVA - 10474 Where is the Marble
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them.
1364 0
uva 100 The 3n+1 problem
题目链接: http://www.programming-challenges.com/pg.php?page=studenthome /* The 3n+1 problem 计算每个数的循环节长度,求给定区间的循环节长度的最大值。 */ #include&lt;iostream&gt; #include&lt;stdio.h&gt; using namespace std;
1151 0
uva 10317 Equating Equations
点击打开链接uva 10317 思路:搜索 分析: 1 给定一个等式判断两边是否相等,如果一个等式相等那么通过移项到同一边可以得到正数的和等于负数 2 那么通过分析1我们可以知道我们可以求出这个等式的所有数字的和,判断和是否为偶数。
736 0
uva 1326 - Jurassic Remains
点击打开链接uva 1326 题意:给定n个由大写字母组成的字符串,选择尽量多的串使得每个大写字母都能出现偶数次 分析: 1 在一个字符串中每个字符出现的次数是无关的,重要的是只是这些次数的奇偶性。
905 0