zoukankan      html  css  js  c++  java
  • A1024 Palindromic Number [回文+大整数加法]

    在这里插入图片描述

    //找质数,找能除的质数
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #include<time.h>
    #include<math.h>
    using namespace std;
    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';
    	}
    	return a;
    }
    bign add(bign a, bign b)
    {
    	bign c;
    	int carry = 0;
    	for (int i = 0; i < a.length||i<b.length; i++)
    	{
    		int temp = a.d[i] +b.d[i] + carry;
    		c.d[c.length++] = temp % 10;
    		carry = temp / 10;
    	}
    	if (carry != 0)
    	{
    		c.d[c.length++] = carry;
    	}
    	return c;
    }
    bool judge(bign a)
    {
    	for (int i = 0; i <= a.length / 2; i++)
    	{
    		if (a.d[i] != a.d[a.length - 1 - i])
    			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];
    	int count = 0, m;
    	cin >> c >> m; 
    	bign a = change(c);
    	while (!judge(a)&&count<m)
    	{
    		bign b = a;
    		reverse(b.d, b.d + b.length);
    		a = add(a, b);
    		count++;
    	}
    	print(a);
    	cout << endl << count;
    
    }
    
  • 相关阅读:
    github中建立pages
    批处理指令_windows定时关机脚本
    批处理指令_同步数据脚本
    python_笔记
    python_操作outlook
    按键精灵_一些踩过的坑
    linux_一些踩过的坑
    python_快速排序
    python_jira库的一些常用操作
    jira_一些踩过的坑
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812039.html
Copyright © 2011-2022 走看看