Sicily 5037. Abacus

本文介绍了一种通过算法模拟算盘的操作过程。该算法能够接收输入,并更新算盘的状态显示,实现加法运算。通过字符串操作实现了算珠的位置变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2012年每周一赛第三场第四题。算盘的模拟,没什么好说的。

Run Time: 0sec

Run Memory: 312KB

Code Length: 634Bytes

SubmitTime: 2012-04-01 21:42:20

// Problem#: 5037
// Submission#: 1300038
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int u, v;
    string thread[ 6 ];
    int i;

    while ( cin >> v && v != -1 ) {
        for ( i = 0; i < 6; i++ )
            cin >> thread[ i ];

        u = 0;
        for ( i = 0; i < 6; i++ )
            u = u * 10 + ( 9 - thread[ i ].find( '-' ) );
        u += v;
        for ( i = 5; i >= 0; i-- ) {
            thread[ i ] = string( 9 - u % 10, 'o' ) + string( 3, '-' ) + string( u % 10, 'o' );
            u /= 10;
        }

        for ( i = 0; i < 6; i++ )
            cout << thread[ i ] << endl;
        cout << endl;
    }

    return 0;

}                                 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值