POJ 2316 SPIN

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6434 Accepted: 3324

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 by only changing them in the allowed groups.

Imagine a row of D numbered wheels, each labeled sequentially with the digits 0 through 9. This is similar to what is on a briefcase combination lock.

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 wheels unchanged.

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

Input

The input to your program will be a line containing 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.There will always be at least 1 digit

Output

Output the final positions of the wheels.

Sample Input

0001
1003
0206
0034
1111
1003

Sample Output

3348

CODE:
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 10 + 5

using namespace std;

int main(){
    char s[MAX_N];
    int ints[MAX_N], ans[MAX_N];
    memset(ans, 0, sizeof(ans));
    int l;
    while(scanf("%s", s + 1) != EOF){
        l = strlen(s + 1);
        REP(i, 1, l) ints[l - i + 1] = s[i] - '0';
        
        int i = 1;
        while(i <= l){
            ans[i] = (ans[i] + ints[i]) % 10;
            i ++;
        }
    }
    REP_(i, 1, l) printf("%d", ans[i]);
    return 0;
}

 


转载于:https://www.cnblogs.com/ALXPCUN/p/4548570.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值