Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ACM Contest Problems Archive University of Valladolid (SPAIN)

483 Word Scramble


Write a program that will reverse the letters in each of a sequence of words while preserving the order
of the words themselves.
Input
The input le will consist of several lines of several words. Words are contiguous stretches of printable
characters delimited by white space.
Output
The output will consist of the same lines and words as the input le. However, the letters within each
word must be reversed.
Sample Input
I love you.
You love me.
We're a happy family.

Sample Output
I evol .uoy
uoY evol .em
er'eW a yppah .ylimaf
ACM Contest Problems Archive University of Valladolid (SPAIN)

591 Box of Bricks


Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks
of di erent height. \Look, I've built a wall!", he tells his older sister Alice. \Nah, you should make all
stacks the same height. Then you would have a real wall.", she retorts. After a little con- sideration,
Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are
the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of
bricks moved. Can you help?

Input
The input consists of several data sets. Each set begins with a line containing the number n of stacks
Bob has built. The next line contains n numbers, the heights h of the n stacks. You may assume
i

1  n  50 and 1  h  100.
i

The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to
rearrange the bricks such that all stacks have the same height.
The input is terminated by a set starting with n = 0. This set should not be processed.
Output
For each set, rst print the number of the set, as shown in the sample output. Then print the line \The
minimum number of moves is k .", where k is the minimum number of bricks that have to be moved
in order to make all the stacks the same height.
Output a blank line after each set.
Sample Input
6
5 2 4 1 7 5
0

Sample Output
Set #1
The minimum number of moves is 5.
UNIVERSIDAD NACIONAL DE INGENIERÍA
Facultad de Ciencias / Ciencia de la Computación
Práctica de Laboratorio 02
Introducción a la Programación (VIE 10:00-12:00h) CC102 - A1
Cada solución debe incluir la explicación de la estrategia a usar y el programa en “C” Duración: 1h 30min

1. (4 puntos) Kindergarten Counting Game/uva:494 


Muchas palabras pueden ser enviadas en cada linea, se 2 12345
trata de construir un programa que reciba estas lineas y 3 67890
determine cuantas palabras tiene cada linea. Una palabra 0 0


esta conformada por una o mas letras consecutivas. Por
ejemplo para el caso: Se retornaria:
 
I did! I did! I did taw a putty tat. −− −− −−
Shsssssssh ... I am hunting wabbits. Heh ... | | | | | |


| | | | | |
Se retornaria: −− −− −− −−
 | | | | |
10 | | | | |
6 −− −− −−


El siguiente bloque de código, estructura la solución, −−− −−− −−− −−− −−−
usted debe escribir el cuerpo de la función cuen- | | | | | | | |
ta palabras: | | | | | | | |
 | | | | | | | |
#include <stdio.h> −−− −−− −−−
int cuenta palabras(char cad[]); | | | | | | | |
int main(){ | | | | | | | |
char cadena[1000]; | | | | | | | |
int n; −−− −−− −−− −−−
while(gets(cadena)){ 

n=cuenta palabras(cadena);
printf (” %d\n”,n);
}
4. (4 puntos) Peter’s Smokes/uva:10346
Peter es un fumador economizador, el tiene n cigarros y
return 0;
ha hallado la forma de armar un nuevo cigarro con k co-
}

 lillas, ayuda a Peter a determinar cuantos cigarros podra


fumar teniendo n y k. En cada linea se ingresa n y k.
Por ejemplo para el caso:
2. (4 puntos) Common Permutation/uva:10252 
Se ingresan cadenas una por linea, para cada par de cade- 10 3
nas ingresadas debera retornar el conjunto de caracteres 100 5
(ordenados alfabeticamente), tal que sea una subcadena 

de alguna permutacion de ambas cadenas, por ejemplo Se retornaria:


para los ingresos: 
 14
walking 124
down 

the

street 5. (4 puntos) 500! /uva:623

El factorial de 500 posee 1135 digitos. Se trata de escribir
Se retornaria: un programa que retorne el factorial de cualquier numero

menor que 1000. Por ejemplo para el caso:
nw 
et 10


30


3. (4 puntos) LC-Display/uva:706 Deberá retornar:

Se debe construir un numeral N, basado en a segmentos.
Se ingresan muchas lineas, un caso por linea, en cada li- 10!
nea se ingresa el valor de N, seguido de a. 3628800
Una linea con 0 0 indica el final de la entrada. Por ejem- 30!
plo para el caso: 265252859812191058636308480000000


(c) Rommel Romero Navarrete / FC 2011, Mayo 6

You might also like