Problem Description

The decimal numeral system is composed of ten digits, which we represent as "0123456789" (the digits in a system are written from lowest to highest).

Imagine you have discovered an alien numeral system composed of some number of digits, which may or may not be the same as those used in decimal.

For example, if the alien numeral system were represented as "oF8", then the numbers one through ten would be (F, 8, Fo, FF, F8, 8o, 8F, 88, Foo, FoF).

We would like to be able to work with numbers in arbitrary alien systems.

More generally, we want to be able to convert an arbitrary number that's written in one alien system into a second alien system.

Input

The first line of input gives the number of cases, N.

N test cases follow. Each case is a line formatted as:

"alien_number source_language target_language"

Each language will be represented by a list of its digits, ordered from lowest to highest value.

No digit will be repeated in any representation, all digits in the alien number will be present in the source language, and the first digit of the alien number will not be the lowest valued digit of the source language
(in other words, the alien numbers have no leading zeroes).

Each digit will either be a number 0-9, an uppercase or lowercase letter, or one of the following symbols !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

0 ≤ alien_number (in decimal) ≤ 1000000000.

2 ≤ num digits in source_language ≤ 94.

2 ≤ num digits in target_language ≤ 94.

Output

For each test case, output one line containing "Case #x: " followed by the alien number translated from the source language to the target language.

Sample Input

4
9 0123456789 oF8
Foo oF8 0123456789
13 0123456789abcdef 01
CODE O!CDE? A? JM!.

Sample Output

Case #1: Foo
Case #2: 9
Case #3: 10011
Case #4: JAM!

传送门:

pid=1038">点击打开链接

解题思路:

进制转换。小模拟。

代码:

#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e6+10;
char s[MAXN], sr[MAXN], to[MAXN], t[MAXN];
map<char, int> mps;
map<int, char> mpt; int main()
{
int icase, w = 1;
scanf("%d", &icase);
getchar();
while(icase--)
{
mps.clear(); mpt.clear();
scanf("%s", s);
scanf("%s", sr);
scanf("%s", to);
//puts(s); puts(sr); puts(to);
int nr = strlen(sr), ns = strlen(s);
int nt = strlen(to);
for(int i=0; i<nr; ++i)
{
mps[sr[i]] = i;
}
for(int i=0; i<nt; ++i)
{
mpt[i] = to[i];
}
int res = 0;
for(int i=0; i<ns; ++i)
{
res = res*nr + mps[s[i]];
}
// printf("%d\n", res);
if(0 == res)
{
printf("Case #%d: ", w++);
printf("%c\n", to[0]);
continue;
}
int cnt = 0;
while(res)
{
t[cnt++] = mpt[(res%nt)];
res /= nt;
}
printf("Case #%d: ", w++);
for(int i=cnt-1; i>=0; --i)
putchar(t[i]);
printf("\n");
}
return 0;
}

Problem Description

Moist has a hobby -- collecting figure skating trading cards. His card collection has been growing, and it is now too large to keep in one disorganized pile. Moist needs to sort the cards in alphabetical order,
so that he can find the cards that he wants on short notice whenever it is necessary.

The problem is -- Moist can't actually pick up the cards because they keep sliding out his hands, and the sweat causes permanent damage. Some of the cards are rather expensive, mind you. To facilitate the sorting,
Moist has convinced Dr. Horrible to build him a sorting robot. However, in his rather horrible style, Dr. Horrible has decided to make the sorting robot charge Moist a fee of $1 whenever it has to move a trading card during the sorting process.

Moist has figured out that the robot's sorting mechanism is very primitive. It scans the deck of cards from top to bottom. Whenever it finds a card that is lexicographically smaller than the previous card,
it moves that card to its correct place in the stack above.
 This operation costs $1, and the robot resumes scanning down towards the bottom of the deck, moving cards one by one until the entire deck is sorted
in lexicographical order from top to bottom.

As wet luck would have it, Moist is almost broke, but keeping his trading cards in order is the only remaining joy in his miserable life. He needs to know how much it would cost him to use the robot to sort his
deck of cards.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

T test cases follow.

Each one starts with a line containing a single integer, N(1 ≤ N ≤ 100).

The next N lines each contain the name of a figure skater, in order from the top of the deck to the bottom.

Each name will consist of only letters and the space character.

Each name will contain at most 100 characters.

No name with start or end with a space.

No name will appear more than once in the same test case.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of dollars it would cost Moist to use the robot to sort his deck of trading cards.

Sample Input

3
2
Oksana Baiul
Michelle Kwan
3
Elvis Stojko
Evgeni Plushenko
Kristi Yamaguchi
4
Evgeni Plushenko
Kristi Yamaguchi
Elvis Stojko
Aksana Baiul

Sample Output

Case #1: 1
Case #2: 0
Case #3: 2

传送门:

pid=1146">点击打开链接

解题思路:

水题,小模拟。

代码:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std; const int MAXN = 110;
char s[MAXN][MAXN];
vector<char *> vec; int main()
{
int w = 1, n, icase;
scanf("%d", &icase);
while(icase--)
{
scanf("%d", &n);
getchar();
vec.clear();
for(int i=0; i<n; ++i)
{
gets(s[i]);
vec.push_back(s[i]);
}
int ans = 0;
for(vector<char *>::iterator it=vec.begin()+1; it!=vec.end(); ++it)
{
if(strcmp(*it, *(it-1)) < 0)
{
vec.erase(it);
--it; ans++;
}
// printf("%s\n", *it);
}
printf("Case #%d: %d\n", w++, ans);
}
return 0;
}

D - Problem D

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

Alex and Bob are brothers and they both enjoy reading very much. They have widely different tastes on books so they keep their own books separately. However, their father thinks it is good to promote exchanges if
they can put their books together. Thus he has bought an one-row bookshelf for them today and put all his sons' books on it in random order. He labeled each position of the bookshelf the owner of the corresponding book ('Alex' or 'Bob').

Unfortunately, Alex and Bob went outside and didn't know what their father did. When they were back, they came to realize the problem: they usually arranged their books in their own orders, but the books seem to
be in a great mess on the bookshelf now. They have to sort them right now!!

Each book has its own worth, which is represented by an integer. Books with odd values of worth belong to Alex and the books with even values of worth belong to Bob. Alex has a habit of sorting his books from the
left to the right in an increasing order of worths, while Bob prefers to sort his books from the left to the right in a decreasing order of worths.

At the same time, they do not want to change the positions of the labels, so that after they have finished sorting the books according their rules, each book's owner's name should match with the label in its position.

Here comes the problem. A sequence of N values s0,
s1, ..., sN-1 is given, which
indicates the worths of the books from the left to the right on the bookshelf currently. Please help the brothers to find out the sequence of worths after sorting such that it satisfies the above description.

Input

The first line of input contains a single integer T(1 ≤ T ≤ 30), the number of test cases.

Each test case starts with a line containing an integer N(1 ≤ N ≤ 1000), the number of books on the bookshelf.

The next line contains N integers separated by spaces, representing s0,
s1, ..., sN-1(-1000 ≤ si ≤
1000), which are the worths of the books.

Output

For each test case, output one line containing "Case #X: ", followed by t0,
t1, ..., tN-1 in order, and
separated by spaces.

X is the test case number (starting from 1) and t0,
t1, ..., tN-1 forms the resulting
sequence of worths of the books from the left to the right.

Sample Input

2
5
5 2 4 3 1
7
-5 -12 87 2 88 20 11

Sample Output

Case #1: 1 4 2 3 5
Case #2: -5 88 11 20 2 -12 87

传送门:

pid=1189">点击打开链接

解题思路:

水题。插入排序。

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e3+10;
int a[MAXN], n, w=1, icase; int main()
{
scanf("%d", &icase);
while(icase--)
{
scanf("%d", &n);
for(int i=0; i<n; ++i)
{
scanf("%d", a+i);
}
for(int i=0; i<n; ++i)
{
if(0 == (a[i]&1)) continue;
int k = i;
for(int j=i+1; j<n; ++j)
{
if((a[j]&1) && a[j]<a[k])
{
k = j;
// printf("%d\n", a[j]);
}
}
swap(a[i], a[k]);
/* for(int j=0; j<n; ++j)
{
printf("%d ", a[j]);
}
printf(" %d\n", a[i]&1);*/
}
for(int i=0; i<n; ++i)
{
if(a[i]&1) continue;
int k = i;
for(int j=i+1; j<n; ++j)
{
if(0==(a[j]&1) && a[j]>a[k])
{
k = j;
// printf("%d\n", a[j]);
}
}
swap(a[i], a[k]);
}
printf("Case #%d:", w++);
for(int i=0; i<n; ++i)
{
printf(" %d", a[i]);
}
printf("\n");
}
return 0;
}

E - Problem E

Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

Good programmers write fabulous comments. Igor is a programmer and he likes the old C-style comments in /* ... */ blocks. For him, it would be ideal if he could use this style as a uniform comment
format for all programming languages or even documents, for example Python, Haskell or HTML/XML documents.

Making this happen doesn't seem too difficult to Igor. What he will need is a comment pre-processor that removes all the comment blocks in /*, followed by comment text, and by another */.
Then the processed text can be handed over to the compiler/document renderer to which it belongs—whatever it is.

Igor's pre-processor isn't quite that simple, though. Here are some cool things it does:

The comments the pre-processor reads can be nested the same way brackets are nested in most programming languages. It's possible to have comments inside comments. For example, the following code block has an outer
level of comments that should be removed by the comment pre-processor. The block contains two inner comments.

printf("Hello /* a comment /* a comment inside comment */
inside /* another comment inside comment */
string */ world");

After the pre-process step, it becomes:

printf("Hello  world");

Igor recognizes comments can appear anywhere in the text, including inside a string "/*...*/", a constant number 12/*...*/34 or even in a character escape \/*...*/n

Or more formally:

text:
text-piece
text-piece remaining-text
text-piece:
char-sequence-without-/*
empty-string
remaining-text:
comment-block text comment-block:
/* comment-content */
comment-content:
comment-piece
comment-piece remaining-comment
comment-piece:
char-sequence-without-/*-or-*/
empty-string
remaining-comment:
comment-block comment-content char:
letters
digits
punctuations
whitespaces

Our pre-processor, given a text, removes all comment-block instances as specified.

Input

A text document with comment blocks in /* and */.

The input file is valid. It follows the specification of text in the problem statement.

The input file always terminates with a newline symbol.

Input contains a program of less than 100k bytes.

The input program contains only:

  • Letters: a-z, A-Z,
  • Digits: 0-9
  • Punctuation: ~ ! @ # % ^ & * ( ) - + = : ; " ' < > , . ?

    | / \ { } [ ] _

  • Whitespace characters: space, newline

Output

We only have one test case for this problem. First we need to output the following line.

Case #1:

Then, print the document with all comments removed, in the way specified in the problem statements.

Don't remove any spaces or empty lines outside comments.

Please output '\n' to finish the case.

Sample Input

//*no recursion*/* file header
***********/************
* Sample input program *
**********/*************
*/
int spawn_workers(int worker_count) {
/* The block below is supposed to spawn 100 workers.
But it creates many more.
Commented until I figure out why.
for (int i = 0; i < worker_count; ++i) {
if(!fork()) {
/* This is the worker. Start working. */
do_work();
}
}
*/
return 0; /* successfully spawned 100 workers */
} int main() {
printf("Hello /*a comment inside string*/ world");
int worker_count = 0/*octal number*/144;
if (spawn_workers(worker_count) != 0) {
exit(-1);
}
return 0;
}

Sample Output

Case #1:
/* file header
************************
*/
int spawn_workers(int worker_count) { return 0;
} int main() {
printf("Hello world");
int worker_count = 0144;
if (spawn_workers(worker_count) != 0) {
exit(-1);
}
return 0;
}

传送门:点击打开链接

解题思路:

手工模拟栈,类似括号匹配的问题。"/*"与“*/”匹配。

用一个数tot记录遇到的"/*"的数量。当tot=0。即没有凝视符,能够将字符直接放到目标数组里,当遇到“*/”而且tot>0时,用掉一个"*/"来和"/*"进行匹配,tot--。

有几个小细节须要注意一下:须要用一个pre记录之前的字符,由于我们须要比較的是连续的两个字符。当遇到"/*"和"*/"时。对pre的更新要留意,pre要更新为接下来要读取的字符;另一个就是对最后一个字符的处理,由于我们每次都是把合法字符(pre)放到结果数组里,所以须要对最后一个字符特殊处理。

几组測试数据:

測试数据:/*/*/**/*/*/

 測试数据: /**/ab

 測试数据: //**/*a*/**/**/

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e3+10;
char out[MAXN];
int m = 0; int main()
{
// freopen("E.txt", "r", stdin);
char c, pre; int tot = 0;
bool flag = false;
pre = getchar();
while((c=getchar()) != EOF)
{
flag = false;
if('/'==pre && '*'==c)
{
++tot;
pre = getchar();
continue;
}
if(0 == tot)
{
flag = true;
out[m++] = pre;
}
if('*'==pre && '/'==c && tot)
{
--tot;
pre = getchar();
continue;
}
pre = c;
}
if(flag) out[m++] = pre;
printf("Case #1:\n");
for(int i=0; i<m; ++i)
{
putchar(out[i]);
}
printf("\n");
return 0;
}

ACdream区域赛指导赛之手速赛系列(5) 题解的更多相关文章

  1. ACdream区域赛指导赛之手速赛系列(2)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/DaiHaoC83E15/article/details/26187183        回到作案现场 ...

  2. ACdream区域赛指导赛之手速赛系列(7)

    A -Dragon Maze Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  3. ACDream手速赛2

    地址:http://acdream.info/onecontest/1014   都是来自Codeforce上简单题.   A. Boy or Girl 简单字符串处理   B. Walking in ...

  4. 快速切题 acdream手速赛(6)A-C

    Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  5. Acdream手速赛7

    蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和 ...

  6. ACdream区域赛指导赛之专题赛系列(1)の数学专场

    Contest : ACdream区域赛指导赛之专题赛系列(1)の数学专场 A:EOF女神的相反数 题意:n(<=10^18)的数转化成2进制.翻转后(去掉前导零)输出十进制 思路:water ...

  7. Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)

    题目列表: 2146 Problem A [手速]阔绰的Dim 2147 Problem B [手速]颓废的Dim 2148 Problem C [手速]我的滑板鞋 2149 Problem D [手 ...

  8. 手速太慢QAQ

    显然D是个细节题,但是还剩1h时看眼榜还没人过EF,只好冷静写D,大概思路是任何时候如果min(n,m)<=2,max(n,m)<=4暴搜,否则直接贪心是很对的,即第一步让S.T长度平均化 ...

  9. tensorflow笔记(四)之MNIST手写识别系列一

    tensorflow笔记(四)之MNIST手写识别系列一 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7436310.html ...

随机推荐

  1. java去左右的空格(包括全角空格,tab,回车等)

    在开发中我们会遇到需要去除左右空格的需求,如果只是简单的空格,调一下trim()方法即可,但如果有中文全角.回车等看起来是空格的非空格,则需要自定义来开发实现,下面这个工具可以实现去左右那些看起来是空 ...

  2. php基础排序算法

    1.冒泡排序 $arr = array(12,34,57,42,165.4,73,51); function bubbling_sort($array) { $cou = count($array); ...

  3. C++ STL容器之 stack

    STL 中的 stack 是一种容器适配器,而不是一种容器. 它是容器适配器是指,只要支持一系列方法的容器(empty, size, back, push_back, pop_back),都能作为st ...

  4. 配置python3 项目环境

    安装python3 安装仓库软件 sudo apt-get install software-properties-common python-software-properties 添加仓库 sud ...

  5. 第七章习题G题

    题意 给出如图案例,要你从某一点开始走,一直走到极限(即无法再进行扩展),这时你走过的点会连成一个数,不同的走法当然会有不同的数,要求是输出最大的数(注意每个方块走过一次就不能再走) 思路 •1.枚举 ...

  6. jQuery中四个绑定事件的区别 on,bind,live,delegate

    1.jQ操作DOM元素的绑定事件的四种方式       jQ中提供了四种事件监听方式,bind.live.delegate.on,对应的解除监听的函数分别是unbind,die,undelegate, ...

  7. 【02】emmet系列之HTML语法

    [01]emmet系列之基础介绍 [02]emmet系列之HTML语法 [03]emmet系列之CSS语法 [04]emmet系列之编辑器 [05]emmet系列之各种缩写 初始化 :快速编写HTML ...

  8. [luoguP1440] 求m区间内的最小值(单调队列 || 线段树)

    传送门 这种水题没必要搞线段树了,单调队列就行啊. ——代码 #include <cstdio> ; , t = ; int a[MAXN], q[MAXN]; int main() { ...

  9. [NOIP2005] 提高组 洛谷P1053 篝火晚会

    题目描述 佳佳刚进高中,在军训的时候,由于佳佳吃苦耐劳,很快得到了教官的赏识,成为了“小教官”.在军训结束的那天晚上,佳佳被命令组织同学们进行篝火晚会.一共有n个同学,编号从1到n.一开始,同学们按照 ...

  10. 【ZJOI2017 Round1练习&BZOJ4773】D3T1 cycle(最小负环,倍增)

    题意:给定一个带权有向图,求点数最小的负环. 2 ⩽ n ⩽ 3000 ⩽ m ⩽ n(n - 1)1 ⩽ ui,vi ⩽ nabs(w[j])<= 10^4 思路:倍增思想 设d[i,j,k] ...