7-5 猜近似数字 (15分)
PTA钻石争霸题
Append code
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main (){
string s1,s2;
cin >>s1;
cin >>s2;
while (s2!="-1"){
if (s1.length()!=s2.length()){
cout <<"NO"<<endl;
}
else {
int mark = 0;int i;
for ( i= 0;i < s1.length();++i){
if (s1[i] == s2[i])continue;
else if (fabs(s1[i]-s2[i]) != 1){
cout <<"NO"<<endl;
break;
}
else if (fabs(s1[i]-s2[i]) == 1 &&mark == 0)mark = 1;
else if (fabs(s1[i]-s2[i]) == 1 &&mark != 0){
cout <<"NO"<<endl;
break;
}
}
if (i ==s1.length())cout <<"YES"<<endl;
}
cin >>s2;
}
}