poj2736大整數相減

來源:互聯網
上載者:User
 
#include<iostream>#include<string.h>using namespace std;char s1[100];char s2[100];int a1[100];int a2[100];int main(){int c[100];int i,j;int str1,str2;int n;cin>>n;for(int l=0;l<n;l++){cin>>s1;cin>>s2;memset(a1,0,sizeof(a1));memset(a2,0,sizeof(a2));str1=strlen(s1);j=0;for(i=str1-1;i>=0;i--){a1[j]=s1[i]-'0';j++;}str2=strlen(s2);j=0;for(i=str2-1;i>=0;i--){a2[j]=s2[i]-'0';j++;}for(j=0;j<str1;j++){if(a1[j]>=a2[j])c[j]=a1[j]-a2[j];else{a1[j+1]--;c[j]=a1[j]+10-a2[j];}}bool bianliang=false;for(i=j-1;i>=0;i--){if(bianliang)cout<<c[i];else if(c[i]){cout<<c[i];bianliang=true;}}if(!bianliang)cout<<0;cout<<endl;}    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.