yuanshitianzun123 2015-12-24 01:03 采纳率: 0%
浏览 1360

C#大数相乘问题,用三个数组来存储

最好用分治法解决问题,然后能够运算20位左右的大数相乘,控制台和窗口都行

  • 写回答

2条回答 默认 最新

  • herozhangbz 2015-12-24 08:36
    关注

    比较难写你再给你个思路吧,你完善下。

    ``` public class dashucheng
    {
    public string cs;//乘数
    public string bcs;//被乘数
    public string cheng()//乘操作返回字符串
    {
    string patten = "^[0-9]{1,}$";
    string[] arr = null;
    System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(patten);//数字匹配
    if (reg.IsMatch(cs) && reg.IsMatch(bcs))
    {
    string a = cs;
    string b = bcs;
    string result;
    int[] c = new int[a.Length];
    int[] d = new int[b.Length];
    int[] f = new int[100];
    arr = new string[a.Length];
    int index = 0;
    for (int i = 0; i < arr.Length; i++)//将字符串格式乘数存放到数组1
    {
    arr[i] = a.Substring(index + i, 1);
    c[a.Length - i - 1] = int.Parse(arr[i]);
    }
    arr = new string[b.Length];
    for (int i = 0; i < arr.Length; i++)//将字符串格式被乘数存放到数组2
    {
    arr[i] = a.Substring(index + i, 1);
    d[b.Length - i - 1] = int.Parse(arr[i]);
    }
    result = a;//进行乘操作赋值给result比较难写没写出来,需要自己写
    return result;
    }
    else if (cs == "" || bcs == "")
    return "empty";
    else
    return "error";
    }
    }
    //click事件内添加下列代码
    dashucheng xc = new dashucheng();
    xc.cs = textBox1.Text;
    xc.bcs = textBox2.Text;
    try
    {
    string result;
    result =xc.cheng();
    if (result != "error" && result != "empty")
    textBox3.Text = result;
    else
    MessageBox.Show(result);
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作