zoukankan      html  css  js  c++  java
  • ocrosoft Contest1316

    http://acm.ocrosoft.com/problem.php?cid=1316&pid=11

    题目描述

    求两个大的正整数相减的差。

     

    输入

    共2行,第1行是被减数a,第2行是减数b(a > b)。每个大整数不超过200位,不会有多余的前导零。

     

    输出

    一行,即所求的差。

     

    样例输入

    9999999999999999999999999999999999999
    9999999999999

    样例输出

    9999999999999999999999990000000000000

    代码:

    #include<stdio.h>
    #include<string.h>
    int main() {
    	int  k = 0;
    	int  a1[255], a2[255], a3[255];
    	char c1[255], c2[255];
    
        memset(a1, 0, sizeof(a1));
        memset(a2, 0, sizeof(a2));
    
    	scanf("%s",c1);
    	scanf("%s",c2);
    
        int str1=strlen(c1);
    	int str2=strlen(c2);
    	int cnt = 0;
    
    	for(int i = str1 - 1; i >= 0; i --)
    	a1[cnt ++] = c1[i] - '0';
    
    	cnt = 0;
    	for(int i = str2 - 1; i >= 0; i --)
    	a2[cnt ++] = c2[i] - '0';
    
        for(int i = 0; i < 255; i ++) {
        	a1[i] -= a2[i];
        	if(a1[i] < 0) {
    	    	a1[i] += 10;
    	    	a1[i + 1] --;
    	    }
        }
    
        cnt = 0;
        for(int i = 254; i >= 0; i --)
         a3[cnt ++] = a1[i];
    
    	for(int i = 0; i < 255; i ++) {
    	if(a3[i] != 0)
            k = 1;
    	if(k == 1)
            printf("%d", a3[i]);
    	}
    	if(k == 0)
            printf("0");
    	printf("
    ");
    	return 0;
    
    }
    

      

  • 相关阅读:
    rc.local文件
    mysql 常用语句模板
    gradle使用
    Elasticsearch 聚合
    华盛顿大学 Programming Languages
    802.11基础
    802.11简单认证过程
    网络诊断错误归类
    802.1X基础
    终端管理软件tmux
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/9728717.html
Copyright © 2011-2022 走看看