[HNU 10042] SpinLock

SpinLock
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
Total submit users: 1142, Accepted users: 874
Problem 10042 : No special judgement
Problem description

Simulate a locked spinner puzzle.

A locked spinner puzzle is a puzzle where you can only change wheels in groups. It is a common puzzle to achieve some value on the spinners with by only changing them in the allowed groups.

Assume a row of D numbered wheels, such as what is found on a combination lock on a briefcase.

 

 

(example: wheels of a briefcase lock)

Each wheel will be labeled sequentially with the digits 0 through 9.  The initial state of the wheels is part of the problem specification.

Below this are a series of B buttons with labels that are D digits long. For example, D may be 4 and the labels are 1000 1200 1002 0111 and 0100. Pressing the button labeled 1000 moves the first wheel once, but leaves the others alone, while pressing the button labeled 1002 moves the first wheel once and the fourth wheel twice, leaving the center button unchanged.

Your task is to simulate such a locked spinner puzzle, providing the final readout of the wheels.


 
Input
The input to your program will be several spinner puzzles. Each puzzle will be D digits (at most 10) representing the starting positions of the wheels. Following this, each line will have the button label for which button is pressed next. The end of each spinner puzzle will be marked with the character ‘x’ alone on a single line. End of the input file will be marked with the character ‘z’.
 
Output
The output file should print the final positions of each spinner puzzle’s wheels. Provide the output header “Spinlock Results” on the first line. Each puzzle follows on a separate line, formatted as below.
 
Sample Input
0001
1003
0206
0034
1111
1003
x
91234567
12340051
33402401
x
z
Sample Output
Spinlock Results
3348
36976919
Problem Source
HNU 1'st Contest

 AC:

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>

int a[10], ch, i = 0, l = 0;

int main()
{
    memset(a, 0, sizeof(a));
    printf("Spinlock Results\n");
    while (~(ch = getchar())) 
    {
        if (ch == '\n') l = i, i = 0;
        else if (ch == 'x') { for (int j = 0; j < l; ++j) printf("%d", a[j] % 10); printf("\n"); memset(a, 0, sizeof(a));}
        else if (ch == 'z') break;
        else a[i++] += ch - '0';
    }
    return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值