HDU2054
来源:互联网 发布:手机淘宝我的积分 编辑:程序博客网 时间:2024/05/17 05:54
这题着实说的不清楚,WA了n次!!!
题目主要考察对字符串的操作,也就是说输入的数可以是很长很长的字符串。
题目也就不再分析了,网上有很多代码。我这里给出一组数据,如果测试正确,AC应该没有问题。
测试数据:
0 -0
0 +0
123.123 +00123.12300
100.00 100
.1 0.1
000.000 0
123456789123456789 123456789123456789
1 1
000001000. 1000
结果:
YES
YES
YES
YES
YES
YES
YES
YES
YES
代码:
/* 处理字符串,正负号以及小数点的位置, 字符指针以字符串数组间的传递问题, 字符串的结束标志是NULL,处理到后 即停止*/#include<iostream>#include<string>using namespace std;#define N 1000000char a[N],b[N];bool judge_p_m(char c[],char d[]) //正负号的处理{ if((c[0]=='-' && d[0]=='-') || (c[0]!='-' && d[0]!='-')) return true; else return false;}char* judge_dec(char e[]){ int i,len,rem=-1; if( e[0]=='+' || e[0]=='-' ) //首字符是+或-时,要去掉 e++; len=strlen(e); for(i=0;i<len;i++) //搜索小数点位置 if(e[i]=='.') { rem=i; break; } if(rem==-1) //无小数点 { for(i=0;i<len;i++) if(e[i]=='0') { e[i]=NULL; } else break; } else if(rem==0) //小数点在最前面 { for(i=len-1;i>=0;i--) if(e[i]=='0' || e[i]=='.') e[i]=NULL; else break; if(e[0]=='.') { for(i=strlen(e);i>0;i--) e[i]=e[i-1]; e[0]='0'; e[strlen(e)+1]=NULL; } } else if(rem==len-1) //小数点在最后面 { e[rem]=NULL; for(i=0;i<len-1;i++) if(e[i]=='0') { e[i]=NULL; } else break; } else //小数点在中间 { for(i=0;i<rem-1;i++) { if(e[i]=='0') { e[i]=NULL; } else break; } for(i=len-1;i>=rem;i--) { if(e[i]=='0' || e[i]=='.') e[i]=NULL; else break; } if( e[rem]==NULL && e[rem-2]==NULL && e[rem-1]=='0' ) e[rem-1]=NULL; } for(i=0;i<len;i++) //搜索字符串第一个非NULL字符的位置 if(e[i]!=NULL) { e=e+i; break; } return e;}int main(){ while(cin>>a>>b) { if( judge_p_m(a,b) ) { if( strcmp( judge_dec(a), judge_dec(b) )==0 ) cout<<"YES"<<endl; else cout<<"NO"<<endl; } else { if( strlen( judge_dec(a) )==0 && strlen( judge_dec(b) )==0 ) cout<<"YES"<<endl; else cout<<"NO"<<endl; } } return 0;}
欢迎拍砖
- HDU2054
- hdu2054
- HDU2054
- hdu2054
- HDU2054
- HDU2054
- HDU2054
- HDU2054(大数的处理)
- 水仙题-hdu2054
- hdu2054(坑爹题)
- hdu2054 A == B ?
- HDU2054:A == B ?
- hdu2054 不要想太多,这就一水题
- HDU2054 A == B?
- HDU2054---A == B ?
- HDU2054 A==B?
- HDU2054--A==B?
- hdu2054 A == B ?
- C++中的引用
- ARM Linux 2.6.36 内核 USB读卡器 测试程序
- C语言模拟虚基类 - 模拟lighttpd fdevent实现
- AndroidManifest 明细
- 5->ORACLE逻辑结构
- HDU2054
- Sicily 1177. Take Your Vitamins
- 算法系列之十一:圆生成算法
- ecshop屏蔽wap功能
- IE6:防止Select等元素遮挡弹出Div层
- 在CentOS下搭建Android 开发环境
- 黑马生活初体验
- linux date命令的用法
- JFreeChart