| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11200 | Tower of Hanoi |
|
| 12057 | Find numbers |
|
Description
The Tower of Hanoi is a mathematical game puzzle. It consists of three rods, which are A, B and C. The puzzle starts with n disks in ascending order of size on rod A, the smallest at the top.
The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:
1. Only one disk can be moved at a time.
2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
3. No disk may be placed on top of a smaller disk.
Write a program to simulate the moves of the disks. Print the number of disk which is moved in each step.
For example, if n = 3, the moves of each steps are:
move disk 1 from rod A to rod C
move disk 2 from rod A to rod B
move disk 1 from rod C to rod B
move disk 3 from rod A to rod C
move disk 1 from rod B to rod A
move disk 2 from rod B to rod C
move disk 1 from rod A to rod C
You should print out:
1
2
1
3
1
2
1
HINT : You can modify this sample code and implement the function 'hanoi'
#include <stdio.h>
void hanoi(int n, char A, char B, char C);
int main(){
int n;
scanf("%d", &n);
hanoi(n, 'A', 'B', 'C');
return 0;
}
Input
An integer n (0<n<20), which means the number of disk.
Output
Print out the number of disk which is moved in each step, and there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an article consists of uppercase/lowercase English characters, digits and space characters (including ' ', '\n'), find out the sum of all numbers contained within the article.
Two digits belong to a same number if and only if there is no any other characters between them.
For example, "I am a 100numbe24r3 5" contains four numbers 100, 24 , 3 and 5, and their sum is 132.
About getchar(): defined in stdio.h, getchar() reads a character (including space characters!) from standard input, returns that characters' ASCII code, or EOF (also defined in stdio.h, usually == -1) if reaches end of file (end of input).
Sample usage:
#include <stdio.h>
char c;
while ((c = getchar()) != EOF) {
printf("%c", c);
}
Input
Input consists of at most 1000 uppercase/lowercase English characters, digits and space characters.
It is guaranteed that all the numbers inside the article is less than 1010.
Output
Print out the sum of all the numbers inside the article.