Problem F
Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 36 Accepted Submission(s) : 5
Problem Description
Give you two numbers A and B, if A is equal to B, you should print “YES”, or print “NO”.
Input
each test case contains two numbers A and B.
Output
for each case, if A is equal to B, you should print “YES”, or print “NO”.
Sample Input
1 2
2 2
3 3
4 3
Sample Output
NO
YES
YES
NO
思路:用字符串输入,在判断是否相同时得先去掉头尾的零;
例如:1.000和00001是“yes”
正确代码:
#include<iostream>
#include<stdio.h>
using namespace std;
int is_xiangtong(string s,string str){
int len=s.length();
for(int i=0;i<len;i++){
if(s[i]!=str[i]){
return 0;
}
}
return 1;
}
string qu_touwei(string s){
int len=s.length();
int i=0;
while(i<len){
if(s[i]!='0'){
break;
}
else{
s.erase(i,1);
len--;
}
//cout<<s<<endl;
}
if(s.find(".")!=s.npos){
len=s.length();
for(i=len-1;i>=0;i--){
if(s[i]=='0'){
s.erase(i,1);
}
else if(s[i]=='.'){
s.erase(i,1);
break;
}
else{
break;
}
}
}
return s;
}
int main(){
string s1,s2;
while(cin>>s1>>s2){
s1=qu_touwei(s1);
s2=qu_touwei(s2);
if(is_xiangtong(s1,s2)){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
//cout<<s1<<endl;
//cout<<s2<<endl;
}
return 0;
}