NYOJ A-B Problem,nyoja-bproblem

來源:互聯網
上載者:User

NYOJ A-B Problem,nyoja-bproblem
A-B Problem時間限制:1000 ms  |  記憶體限制:65535 KB難度:3

描述

A+B問題早已經被大家所熟知了,是不是很無聊呢?現在大家來做一下A-B吧。

現在有兩個實數A和B,聰明的你,能不能判斷出A-B的值是否等於0呢?

輸入
有多組測試資料。每組資料包括兩行,分別代表A和B。
它們的位元小於100,且每個數字前中可能包含+,- 號。
每個數字前面和後面都可能有多餘的0。
每組測試資料後有一空行。
輸出
對於每組資料,輸出一行。
如果A-B=0,輸出YES,否則輸出NO。
範例輸入
111.02.0
範例輸出
YESNO
 #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;char s[110],str[110];int main(){int i,j,l,n,k,flag,sign,a,b,c,d,e,g;while(scanf("%s",s)!=EOF){getchar();scanf("%s",str);sign=flag=e=g=0;l=strlen(s);n=strlen(str);c=l-1;d=n-1;for(i=0;i<l;++i){if(s[i]=='-')sign=1;if(s[i]!='0'&&s[i]!='-'&&s[i]!='+')break;}for(j=0;j<n;++j){if(str[j]=='-')flag=1;if(str[j]!='0'&&str[j]!='-'&&str[j]!='+')break;}a=i;b=j;if(strchr(s,'.')){for(i=l-1;i>=0;--i){if(s[i]!='0')break;}c=i;if(s[c]=='.')c--;}if(strchr(str,'.')){for(j=n-1;j>=0;--j){if(str[j]!='0')break;}d=j;if(str[d]=='.')d--;}if(a>b){for(i=b;i<=d;++i){if(s[i-b+a]!='0'&&s[i]-b+a!='.')e=1;if(str[i]!='0'&&str[i]!='.')g=1;if(s[i-b+a]!=str[i])break;}if(i==(d+1)&&(i-b+a)==(c+1)&&(sign==flag||e==0&&g==0))printf("YES\n");else printf("NO\n");}else{for(j=a;j<=c;++j){if(s[j]!='0'&&s[j]!='.')e=1;if(str[j-a+b]!='0'&&str[i-b+a]!='.')g=1;if(s[j]!=str[j-a+b])break;}if(j==(c+1)&&(j-a+b)==(d+1)&&(sign==flag||e==0&&g==0))printf("YES\n");else printf("NO\n");}}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.