这道题......被我各种姿势搞死的...
本题大意:给出两个数A和B,判断A和B是否相等,对应输出YES or NO。
本题思路:本题我有两种思路,第一种是直接去除前导零和后导零然后稍加处理比较字符串即可,第二种是找出每个字符串的 '.' 然后向两边搜索即可,下面给出第一种思路的代码,仅供参考,建议读者自行实现。
参考代码:
1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 5 const int maxn = 1e8; 6 int begina, beginb, enda, endb, point1, point2, len1, len2; 7 bool flag; 8 char a[maxn], b[maxn]; 9 10 int main () { 11 while(~scanf("%s %s", a, b)) { 12 flag = true; 13 point1 = point2 = maxn; 14 len1 = strlen(a), len2 = strlen(b); 15 if(strchr(a, '.')) 16 point1 = strchr(a, '.') - a; 17 if(strchr(b, '.')) 18 point2 = strchr(b, '.') - b; 19 begina = -1, beginb = -1, enda = len1, endb = len2; 20 for(int i = 0; i < len1; i ++)// find begina 21 if(a[i] == '0' && i < point1) begina = i; 22 else break; 23 for(int i = 0; i < len2; i ++)// find beginb 24 if(b[i] == '0' && i < point2) beginb = i; 25 else break; 26 for(int i = len1 - 1; i >= point1; i --)// find enda 27 if(a[i] == '0') enda = i; 28 else if(a[i] == '.') enda = i; 29 else break; 30 for(int i = len2 -1; i >= point2; i --)// find endb 31 if(b[i] == '0') endb = i; 32 else if(b[i] == '.') endb = i; 33 else break; 34 int i = begina + 1; 35 for(int j = beginb + 1; i < enda; j ++) 36 if(a[i ++] != b[j]) { 37 printf("NO "); 38 flag = false; 39 break; 40 } 41 if(flag) printf("YES "); 42 } 43 return 0; 44 }