#include<stdio.h> #include<string> #include<iostream> using namespace std; string s1,s2; int main() { int i,j; while(cin>>s1>>s2) { int sub=s1.size()-s2.size(); if(sub>0) { for(j=0;j<s2.size();j++) if(s2[j]=='.')break; if(j==s2.size()) { s2.push_back('.'); while(s2.size()<s1.size()) s2.push_back('0'); } else { while(s2.size()<s1.size()) s2.push_back('0'); } } else if(sub<0) { for(j=0;j<s1.size();j++) if(s1[j]=='.')break; if(j==s1.size()) { s1.push_back('.'); while(s1.size()<s2.size()) s1.push_back('0'); } else { while(s1.size()<s2.size()) s1.push_back('0'); } } //cout<<s1<<" "<<s2<<endl; for(i=0,j=0;i<s1.size(),j<s2.size();i++,j++) { if(s1[i]!=s2[j])break; } if(i==s1.size())printf("YES\n"); else printf("NO\n"); s1.clear(); s2.clear(); } return 0; }
题解:
字符串s1,s2,相比较,个数小的后面补0(题意明确说明为数字,不会前导0)
关键在于如何补0(针对需要补0 的字符串):
1.若出现过小数点,则直接后补0;
2,否则需补小数点‘ . ’ 后,再补齐0.