zoukankan      html  css  js  c++  java
  • 424 Integer Inquiry

    水题,就是把非常大的数组进行相加

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    char table_atoi[128];//下标字母 对应  数字
    int main()
    {
    	int i =0;
    	char c = '0';
    	for( ; i < 10 ; ++i ,++c)
    	{
    		table_atoi[c] = i;
    
    	}
    	char buff[100];
    	char result[100] = {0};
    	char carry = 0;
    	int result_len = 0;
    	int temp;
    	while(cin>>buff)
    	{
    		if(buff[0] == '0') break;
    		int len = strlen(buff)-1;//从个位开始
    		i= 0;
    		carry = 0;
    		while(len >= 0)
    		{
    			temp = table_atoi[buff[len]]+result[i]+carry;
    			carry = (temp>=10?1:0);
    			temp = (carry ==0 ? temp:temp-10);
    			result[i] = temp;
    			i++;
    			len --;
    		}
    		if(carry != 0)
    		{
    			while(carry != 0)
    			{
    				temp = result[i]+carry;
    				carry = (temp>=10?1:0);
    				temp = (carry ==0 ? temp:temp-10);
    				result[i++] = temp;
    			}
    		}
    		if(i > result_len) result_len = i;
    	}
    
    	result[result_len] = 0;
    	reverse(result,result+result_len);
    	transform(result,result+result_len,result,bind2nd(plus<int>(),48));
    	cout<<result<<endl;
    	cin>>i;
    	return 0;
    }
    
  • 相关阅读:
    渣渣的python的上路
    【tyvj 2038】诡异的数学题
    codeforces_733_A
    NOIP2011 选择客栈
    NOIP 2012 同余方程
    灵渊(seals.cpp/c/pas)
    NOIP 2012 开车旅行
    Mybatis初步详细配置
    SpringMVC之编程式校验
    Spring整合MyBaytis
  • 原文地址:https://www.cnblogs.com/UnGeek/p/2562868.html
Copyright © 2011-2022 走看看