(ZJU-2006复试)-ZOJ-2529-A+B in Hogwarts

 

A+B in Hogwarts
Time Limit: 1 Second       Memory Limit: 32768 KB

If you are a fan of Harry Potter, you would know the school he is attending to, the Hogwarts School for Witchcraft and Wizardry. What you might not know is that Harry is never good at math, yet he doesn't want to bother Hermione for trivial A+B problems. Now your job is to write a simple calculator for him -- the calculator is so simple that it handles non-negative integer additions only.

What is not so simple is that the world of Witchcraft and Wizardry dosen't use a fixed radix numeration system. That is, an integer is represented with different radices for different digits -- the radix for the i-th digit is the i-th prime number. For example, the decimal number 2 is 10 in Hogwarts (let's denote it by 210 = 1,0H) since the radix for the 1st digit is the 1st prime number 2. Similarly we have 610 = 1,0,0Hsince the radix for the 2nd digit is 3.

Input

The input consists of multiple test cases, each occupies a line with two integers in Hogwarts' system. Digits of a Hogwarts' integer are seperated by ',' and the two numbers are seperated by a space. Each number has at most 25 digits.

Output

For each test case, print in one line the sum of the two given numbers in Hogwarts' system.

Sample Input

1,0 2,1
4,2,0 1,2,0
1 10,6,4,2,1

Sample Output

1,0,1
1,1,1,0
1,0,0,0,0,0
 
就是一个不同进制的大数加法。。可惜本人基本功不过关,这道题费了很多时间,这里是浙大上的题目,杭电上的输入输出稍有不同
代码用了一些不必要的变量
测试的时候考虑如下数据
0,0,0 0,0,0
0

0,1,0,1 0,0,1,1

1,2,0

 

96,88,82,78,72,70,66,60,58,52,46,42,40,36,30,28,22,18,16,12,10,6,4,2,1 96,88,82,78,72,70,66,60,58,52,46,42,40,36,30,28,22,18,16,12,10,6,4,2,1

1,96,88,82,78,72,70,66,60,58,52,46,42,40,36,30,28,22,18,16,12,10,6,4,2,0

 

 

#include <iostream>
#include <string>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;

int prime[28]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29,31, 
            37, 41, 43, 47, 53, 59, 61, 67, 71,73, 79, 83, 89, 97,101,103, 107};

int a[30],b[30];
int c[30];
int main()
{
    string ta,tb;
    while(cin>>ta>>tb)
    {    
        int temp=0,j=0,k=0;
        for(int i=ta.length()-1;i>=0;--i)
        {
            if(ta[i]==',')
            {
                a[k++]=temp;
                temp=0;
                j=0;
            }
            else
            {
                temp+=(ta[i]-48)*pow(10.0, j*1.0);
                ++j;
            }
        }
        a[k]=temp;
        int lena=k+1;
        temp=0;j=0;k=0;
        for(int i=tb.length()-1;i>=0;--i)
        {
            if(tb[i]==',')
            {
                b[k++]=temp;
                temp=0;
                j=0;
            }
            else
            {
                temp+=(tb[i]-48)*pow(10.0, j*1.0);
                ++j;
            }
        }
        b[k]=temp;
        int lenb=k+1;   
        int carry=0;
        int len=lena<lenb?lena:lenb;
        
        memset(c,0,sizeof(c));
        
        for(int i=0;i<len;++i)
        {
            c[i]=(carry+a[i]+b[i])%prime[i];
            carry=(carry+a[i]+b[i])/prime[i];
        }

        if(lena<lenb)
        {
            for(int i=lena;i<lenb;++i)
                if(carry)
                { 
                    c[i]=(carry+b[i])%prime[i];
                    carry=(carry+b[i])/prime[i];
                }
                else c[i]=b[i];
                
        }
        else
        {    
            for(int i=lenb;i<lena;++i)
                if(carry)
                { 
                    c[i]=(carry+a[i])%prime[i];
                    carry=(carry+a[i])/prime[i];
                }
                else c[i]=a[i];
        }
        len=lena>lenb?lena:lenb;
        while(carry)
        {
            c[len]=carry%prime[len];
            carry=carry/prime[len];
            ++len;
        }

        len--;
        while(c[len]==0&&len>0)len--;
        cout<<c[len];
        for(int i=len-1;i>=0;--i)
            cout<<","<<c[i];
        cout<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ZJU-I型机械臂是一种由浙江大学机器人研究所开发的六自由度机械臂,具有高速、精度和可靠性等特点。机械臂的运动控制是机器人中的重要研究领域之一,其中点到点轨迹规划是机器人在运动过程中最基础和常用的一种方式,也是机械臂控制的核心问题之一。 点到点轨迹规划的目标是通过给定的起点和终点,计算出机械臂的运动轨迹,使机械臂在运动过程中满足机械臂轨迹的连续性、平滑性、可控性等要求。在过去的研究中,经典的点到点轨迹规划方法包括插值法、线性规划法、最小能量法等。 如果使用Python实现机械臂的点到点轨迹规划,可以采用Robotics Toolkit(简称robot)这个模块。robot模块提供了各种从轨迹规划、控制到仿真的功能,可用于ROS、Vrep、Webots等机器人仿真软件。使用robot模块,可以通过几行代码实现机械臂的点到点轨迹规划,例如: ``` from roboticstoolkit import robot from roboticstoolkit.robots import zju # 初始化机器人 zju_arm = robot.Robot('zju', zju.URDF) # 设定起点和终点 start = [0, 0, 0, 0, 0, 0] goal = [0, 1, 1, 0.5, 0, 0] # 计算机械臂的轨迹 path = zju_arm.get_trajectory(start, goal) # 控制机械臂运动到终点 zju_arm.move_to(goal) ``` 其中,`roboticstoolkit`和`roboticstoolkit.robots`都是导入的Python模块,`zju`是机械臂的URDF定义文件,`start`和`goal`是起点和终点的坐标,`get_trajectory()`函数会返回计算得到的机械臂轨迹,`move_to()`函数则控制机械臂运动到终点。 总之,使用Python实现ZJU-I型机械臂的点到点轨迹规划相对简单,只需要导入相应的模块,并根据需要设置机械臂的各种参数,即可轻松实现机械臂的控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值