比大小

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
 
描述

给你两个很大的数,你能不能判断出他们两个数的大小呢?

比如123456789123456789要大于-123456

 
输入
每组测试数据占一行,输入两个不超过1000位的10进制整数a,b
数据保证输入的a,b没有前缀的0。
如果输入0 0表示输入结束。测试数据组数不超过10组
输出
如果a>b则输出“a>b”,如果a<b则输出“a<b”,如果相等则输出“a==b”。
样例输入
111111111111111111111111111 88888888888888888888
-1111111111111111111111111 22222222
0 0
样例输出
a>b
a<b
 //NYOJ-比大小
//大数模板
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<cstdio>
using namespace std;
#define MAXN 9999
#define MAXSIZE 10
#define DLEN 4
char str1[],str2[];
class BigNum
{
private:
int a[];
int len;
public:
BigNum(){ len = ;memset(a,,sizeof(a)); }
BigNum(const char*);
bool operator > (const BigNum & T)const;
};
BigNum::BigNum(const char*s){
int t,k,index,l,i;
memset(a,,sizeof(a));
l=strlen(s);
len=l/DLEN;
if(l%DLEN)
len++;
index=;
for(i=l-;i>=;i-=DLEN)
{
t=;
k=i-DLEN+;
if(k<)
k=;
for(int j=k;j<=i;j++)
t=t*+s[j]-'';
a[index++]=t;
}
}
bool BigNum::operator>(const BigNum & T) const
{
int ln;
if(len > T.len)
return true;
else if(len == T.len)
{
ln = len - ;
while(a[ln] == T.a[ln] && ln >= )
ln--;
if(ln >= && a[ln] > T.a[ln])
return true;
else
return false;
}
else
return false;
} int main(){
while(~scanf("%s %s",str1,str2)){
if(str1[]=='' && str2[]==''){
break;
}
BigNum big1(str1);
BigNum big2(str2);
if(strcmp(str1,str2) == ){
printf("a==b\n");
}else if(str1[] == '-' && str2[] == '-'){
big1 > big2 ? printf("a<b\n") : printf("a>b\n");
}else if(str1[] == '-' && str2[] != '-'){
printf("a<b\n");
}else if(str2[] == '-' && str1[] != '-'){
printf("a>b\n");
}else{
big1 > big2 ? printf("a>b\n") : printf("a<b\n");
}
}
return ;
}
 //最优解
#include<iostream>
#include<string>
using namespace std; int main()
{
string a,b;
while(cin>>a>>b)
{
if(a==""&&b=="")
return ;
if(a==b)
cout<<"a==b"<<endl;
else if(a[]=='-'&&b[]=='-')
{
if(a.substr(,string::npos)>b.substr(,string::npos)||a.length()>b.length())
cout<<"a<b"<<endl;
else cout<<"a>b"<<endl;
}
else if(a>""&&b>""||a<""&&b<""&&a.length()>b.length()||a>b)
cout<<"a>b"<<endl;
else if(a<""&&b>""&&a.length()>b.length()||a>b)
cout<<"a<b"<<endl; }
}

【大数比较】NYOJ-73的更多相关文章

  1. 大数阶乘 nyoj

    大数阶乘 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?   输入 输入一个整数 ...

  2. nyoj 73 比大小

    点击打开链接 比大小 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 给你两个很大的数,你能不能判断出他们两个数的大小呢? 比如123456789123456789要大于 ...

  3. nyoj 28 大数阶乘

    题目链接:nyoj 28 就是个简单的高精度,只是一开始我打表超内存了,然后用了各种技巧硬是把内存缩到了题目要求以下(5w+kb),感觉挺爽的,代码如下: #include<cstdio> ...

  4. nyoj 1091 还是01背包(超大数dp)

    nyoj 1091 还是01背包 描述 有n个重量和价值分别为 wi 和 vi 的物品,从这些物品中挑选总重量不超过W的物品,求所有挑选方案中价值总和的最大值 1 <= n <=40 1 ...

  5. nyoj 28-大数阶乘 (大数模板)

    28-大数阶乘 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:19 submit:39 题目描述: 我们都知道如何计算一个数的阶乘,可是,如果这个数 ...

  6. NYOJ题目28大数阶乘

    -------------------------------------祭出BigInteger AC代码: import java.math.BigInteger; import java.uti ...

  7. nyoj 803 大数问题

    #include<stdio.h> #include<string.h> #define ll long long #define N 110000 int main() { ...

  8. nyoj 103-A+B Problem II (python 大数相加)

    103-A+B Problem II 内存限制:64MB 时间限制:3000ms 特判: No 通过数:10 提交数:45 难度:3 题目描述: I have a very simple proble ...

  9. Java的大数操作分为BigInteger和BigDecimal

    Java的大数操作分为BigInteger和BigDecimal,但这两给类是分开使用的,有时候在编程的时候显得略微繁琐,现在编写了一个将二者合二为一的大数操作类. 大数操作类代码如下: 1 pack ...

  10. HDU 5832 A water problem (水题,大数)

    题意:给定一个大数,问你取模73 和 137是不是都是0. 析:没什么可说的,先用char 存储下来,再一位一位的算就好了. 代码如下: #pragma comment(linker, "/ ...

随机推荐

  1. uva 11489

    简单博弈 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #i ...

  2. jquery中判断是否按下回车enter键

    <script>   function sendsubmit()   {   $("#userLoginForm").submit();   return false; ...

  3. php数组函数序列之array_unshift() 在数组开头插入一个或多个元素

    array_unshift() 函数在数组开头插入一个或多个元素.被加上的元素作为一个整体添加,这些元素在数组中的顺序和在参数中的顺序一样 array_unshift()定义和用法 array_uns ...

  4. oracle触发器详解(转)

    触发器是许多关系数据库系统都提供的一项技术.在ORACLE系统里,触发器类似过程和函数,都有声明,执行和异常处理过程的PL/SQL块. 8.1 触发器类型 触发器在数据库里以独立的对象存储,它与存储过 ...

  5. 【PHPsocket编程专题(理论篇)】初步理解TCP/IP、Http、Socket.md

    前言 我们平时说的最多的socket是什么呢,实际上socket是对TCP/IP协议的封装,Socket本身并不是协议,而是一个调用接口(API).那TCP/IP又是什么呢?TCP/IP是ISO/OS ...

  6. 什么是hibernate?

    一.什么是hibernate框架?1.通过数据库保存java运行时产生的对象和恢复对象,其实就是实现java对象与关系数据库记录的映射关系称为ORM(Object Relation Mapping), ...

  7. 移植 FFMPEG-2.2.4 -(编译)

    源码下载:http://www.ffmpeg.org/download.html编译安装: http://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu su ...

  8. python 下划线的使用(转载:安生犹梦 新浪博客)

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx      不能用'from module import *'导入 __xxx__ 系统定义名字 __xxx    类中的私有变量名 核 ...

  9. Ado.Net小练习03(省市联动)

    前台界面:          后台代码: namespace _04省市联动 {     public partial class Form1 : Form     {         public ...

  10. asp.net(C#)读取word 文档的方法

    第一种方法 Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "Application/msw ...