• A1023 Have Fun with Numbers [大整数乘法]


    在这里插入图片描述

    //找质数,找能除的质数
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #include<time.h>
    #include<math.h>
    using namespace std;
    typedef long long ll;
    int hashtable[10];
    struct bign
    {
    	int d[1001];
    	int length;
    	bign()
    	{
    		memset(d, 0, sizeof(d));
    		length = 0;
    	}
    };
    bign change(char str[])
    {
    	bign a;
    	a.length = strlen(str);
    	for (int i = 0; i < a.length; i++)
    	{
    		a.d[i] = str[a.length - i - 1] - '0';
    		hashtable[a.d[i]]++;
    	}
    	return a;
    }
    bign multi(bign a, int b)
    {
    	bign c;
    	int carry = 0;
    	for (int i = 0; i < a.length; i++)
    	{
    		int temp = a.d[i] * b + carry;
    		c.d[c.length++] = temp % 10;
    		carry = temp / 10;
    	}
    	while (carry != 0)
    	{
    		c.d[c.length++] = carry % 10;
    		carry /= 10;
    	}
    	return c;
    }
    bool iscout(bign r)
    {
    	for (int i = r.length - 1; i>= 0; i--)
    	{
    		hashtable[r.d[i]]--;
    	}
    	for (int i = 0; i <10; i++)
    	{
    		if (hashtable[i] !=0)
    			return false;
    	}
    	return true;
    }
    void print(bign a)
    {
    	for (int i = a.length - 1; i >= 0; i--)
    	{
    		cout << a.d[i];
    	}
    }
    int main()
    {
    	char c[1001];
    	cin >> c;
    	bign a = change(c);
    	bign b = multi(a, 2);
    	if (iscout(b))
    	{
    		cout << "Yes" << endl;
    		print(b);
    	}
    	else
    	{
    		cout << "No" << endl;
    		print(b);
    	}
    
    }
    
  • 相关阅读:
    MVC 小demo
    单例模式
    简单工厂模式
    有关ajax中的URL问题
    SqlHelper++
    C# 操作XML
    C# 注册DLL(使用cmd)
    图片延迟加载库Layzr
    解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.
    HTML5 + SOCKET视频传输
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812040.html
Copyright © 2020-2023  润新知