10785 - The Mad Numerologist
来源:互联网 发布:云智能网络 编辑:程序博客网 时间:2024/06/06 02:24
题目:10785 - The Mad Numerologist
题目大意:就是给定字符串长度,要求要找到一个总值最小,并且奇数位,偶数位按字典序的字符串。
解题思路:要求值最小,就按照题目给的各个字母的值,给出两个从左到右值一次增大的常量字符串,(元音辅音分开两个字符串)。最终结果的字符串要求用到的辅音不能重复超过5次,元音不能重复超过21次。
可是值小的字母,字典序不一定也排前,所以要奇数位,偶数位分别按字典序sort(),因此要开两个数组分别给奇数位,偶数位,最后排好序再交替输出。小心输出结果的case 1: AJ. 冒号后面有一个空格。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const char v[] = "AUEOI";const char c[] = "JSBKTCLDMVNWFXGPYHQZR"; const int N = 200;char o[N], e[N];int n, len;int cmp(char a, char b) {return a < b;}int main() {int i, j;scanf("%d", &n);for(i = 0; i < n; i++) {scanf("%d", &len);int odd = (len + 1) / 2;int even = len / 2;for(j = 0; j < odd; j++) o[j] = v[j/21];for(j = 0; j < even; j++)e[j] = c[j/5];sort(o, o + odd, cmp);sort(e, e + even, cmp);printf("Case %d: ", i + 1);int s1,s2;s1 = s2 = 0;for(j = 0; j < len; j++) {if(j % 2 == 0) {printf("%c", o[s1]);s1++;}else {printf("%c", e[s2]);s2++;}}printf("\n");}return 0;}
0 0
- 10785 - The Mad Numerologist
- 10785-The Mad Numerologist
- 10785 - The Mad Numerologist
- 10785 - The Mad Numerologist
- uva 10785 The Mad Numerologist
- uva 10785 - The Mad Numerologist
- UVA 10785 - The Mad Numerologist
- UVaOJ 10785 - The Mad Numerologist
- Uva 10785 - The Mad Numerologist
- uva 10785The Mad Numerologist
- UVa 10785 - The Mad Numerologist
- UVA 10785 The Mad Numerologist
- UVA 10785 - The Mad Numerologist
- uva 10785 The Mad Numerologist
- UVa 10785 - The Mad Numerologist
- UVa:10785 - The Mad Numerologist
- UVa 10785 - The Mad Numerologist
- UVa 10785 - The Mad Numerologist
- matlab学习笔记009之solve函数
- 给程序员的建议
- 重写
- xshell 配色方案
- 开源MSP430F147单片机软核添加自定义外设
- 10785 - The Mad Numerologist
- libxml2对XML文件的创建、解析、查找、修改
- Linux设备模型(三)platform
- [性能调整] ORACLE分区表、分区索引详解(转)
- Leetcode: Subsets
- Lightoj 1170 卡特兰数+扩展欧几里得算法
- ARM7 Timer与DMA的register
- mac 10.9 虚拟机分辨率问题
- 网络分析,图挖掘常用数据集:dblp dataset,kdd dataset....