这道题目起初看,so easy。再看一下ac率,注意到没有说明变量类型。显然是一道字符串的题。需要考虑+/-符号位,+.1、-.1、00010.0、+0、-00.00等情况,同时数组开到100000以上。wa了两次,第二次是才发现输出的是YES/NO,我一直输出的是yes/no,测了很多数据都是对的才发现是大小写错误,巨坑,而且代码写的也挺乱。
#include <stdio.h> #define MAXNUM 110000 char a[MAXNUM];
char b[MAXNUM]; void chg(char a[]) {
int i, beg, end, tmp; tmp = strlen(a);
if (a[] != '+' && a[] != '-') {
for (i=tmp; i>=; --i)
a[i+] = a[i];
a[] = '+';
tmp++;
} beg = ;
while (beg<tmp && a[beg] == '')
beg++; if (beg) {
if (beg> && a[beg] == '.')
beg--;
if (beg == tmp)
beg--;
for(i=beg; i<=tmp; ++i)
a[i-beg+] = a[i];
} tmp = ;
for (i=; i<strlen(a); ++i)
if (a[i] == '.') {
tmp = i;
break;
} if (tmp == ) {
tmp = strlen(a);
if (tmp== && a[]=='')
a[] = '+';
return ;
} else if (tmp == ) {
end = strlen(a);
for (i=end; i>=tmp; --i)
a[i+] = a[i];
a[tmp] = '';
tmp++;
} end = strlen(a) - ;
while (end>tmp && a[end] == '')
end--; if ( end == tmp )
a[end] = '\0';
else
a[end+] = '\0'; tmp = strlen(a);
if (tmp == && a[] == '')
a[] = '+';
} int main() {
int len1, len2;
int i, flg; while (scanf("%s %s", a, b) != EOF) {
chg(a);
chg(b);
len1 = strlen(a);
len2 = strlen(b);
//printf("%s\n", a);
//printf("%s\n", b);
if (len1 != len2)
printf("NO\n");
else {
flg = ;
for (i=; i<len1; ++i)
if (a[i] != b[i]) {
flg = ;
break;
}
if (flg)
printf("YES\n");
else
printf("NO\n");
}
} return ;
}