C++ 比大小
//输入两个可能有前导 0 的大整数,a,b请输出他们谁大谁小 #include <iostream> #include <string> #include <string.h> using namespace std; #define M 100005 int main() { char a[M], b[M]; char *pa, *pb; pa = a; pb = b; cin >> a >> b; while(*pa == '0')pa++; while(*pb == '0')pb++; if(strlen(pa) > strlen(pb)){ cout<<"first"<<endl; } else if(strlen(pa) < strlen(pb)){ cout<<"second"<<endl; } else{ int res = strcmp(pa, pb); if(res > 0){ cout<<"first"<<endl; }else if(res < 0){ cout<<"second"<<endl; } else{ cout<<"same"<<endl; } } return 0; }
原文地址:https://blog.csdn.net/laocooon/article/details/142901043
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!