Codeforces 66A:Petya and Java(水题)

Fritzing0.9.10下载安装和简单使用 Fritzing 作为一款电子设计自动化软件,其画图用于导入到论文和文档,清晰好看,能解决用相机拍实物照片杜邦线很乱的痛点。 阅读详情
A. Petya and Java
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is the best choice. The main argument in favor of choosing Java was that it has a very large integer data type, called BigInteger.

But having attended several classes of the club, Petya realized that not all tasks require using the BigInteger type. It turned out that in some tasks it is much easier to use small data types. That's why a question arises: "Which integer type to use if one wants to store a positive integer n?"

Petya knows only 5 integer types:

1) byte occupies 1 byte and allows you to store numbers from  - 128 to 127

2) short occupies 2 bytes and allows you to store numbers from  - 32768 to 32767

3) int occupies 4 bytes and allows you to store numbers from  - 2147483648 to 2147483647

4) long occupies 8 bytes and allows you to store numbers from  - 9223372036854775808 to 9223372036854775807

5) BigInteger can store any integer number, but at that it is not a primitive type, and operations with it are much slower.

For all the types given above the boundary values are included in the value range.

From this list, Petya wants to choose the smallest type that can store a positive integer n. Since BigInteger works much slower, Peter regards it last. Help him.

Input

The first line contains a positive number n. It consists of no more than 100 digits and doesn't contain any leading zeros. The number ncan't be represented as an empty string.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

Output

Print the first type from the list "byte, short, int, long, BigInteger", that can store the natural number n, in accordance with the data given above.

Examples
input
127
output
byte
input
130
output
short
input
123456789101112131415161718192021222324
output
BigInteger





题意:给你一个数,根据题意所给数的范围,确定并输出出这个数的类型。
解题思路:这个题上说最多有100位的数,肯定是大数了,那么就用字符串来储存所输入的数字。然后处理这个数字:分三种情况:①位数小于19位的,肯定能用一个long long型变量储存,然后再用普通方法判断这个数的类型(肯定是long型,int型,short型,byte型了);②位数等于19位的,用strcmp函数将9223372036854775807与字符串进行比较(返回值大于等于0说明所输入的数字小于等于9223372036854775807,是long型,返回值小于0说明所输入的数字大于9223372036854775807,是BigInteger型);③位数大于19位的,肯定是BigInteger型了。。。

刚开始没看清题,以为输入的数字可正可负,就把负数情况也顺便判断了下,方法与正数判断一样,把临界值和strcmp返回值改改就行。。

#include <stdio.h>
#include <string.h>
int main()
{
	char s[110];
	while(scanf("%s",s)!=EOF)
	{
		int size=strlen(s);
		if(s[0]=='-')
		{
			if(size==20)
			{
				if(strcmp("-9223372036854775808",s)>=0)
				{
					printf("long\n");
				}
				else
				{
					printf("BigInteger\n");
				}
			}
			if(size<20)
			{
					long long tmp=0;
					long long ci=1;
					for(int i=size-1;i>0;i--)
					{
						tmp=tmp+ci*(s[i]-'0');
						ci=ci*10;
					}
					if(tmp>2147483648)
					{
						printf("long\n");
					}
					else
					{
						if(tmp>32768)
						{
							printf("int\n");
						}
						else
						{
							if(tmp>128)
							{
								printf("short\n");
							}
							else
							{
								printf("byte\n");
							}
						}
					}
			}
			if(size>20)
			{
				printf("BigInteger\n");
			}
		}
		else
		{
			if(size==19)
			{
				if(strcmp("9223372036854775807",s)>=0)
				{
					printf("long\n");
				}
				else
				{
					printf("BigInteger\n");
				}
			}
			if(size<19)
			{
					long long tmp=0;
					long long ci=1;
					for(int i=size-1;i>=0;i--)
					{
						tmp=tmp+ci*(s[i]-'0');
						ci=ci*10;
					}
					if(tmp>2147483647)
					{
						printf("long\n");
					}
					else
					{
						if(tmp>32767)
						{
							printf("int\n");
						}
						else
						{
							if(tmp>127)
							{
								printf("short\n");
							}
							else
							{
								printf("byte\n");
							}
						}
					}
			}
			if(size>19)
			{
				printf("BigInteger\n");
			}
		}
	}
	return 0;
}



V2签名预装失败原因及解决方案 GOOGLE最新的GTS要求targetSdkVersion 大于30的APK必须使用V2及以上签名。 但实际在预装过程中,GTS测试会失败。 后面发现这是由于预装方式的原因造成的。原来的预装方式是使用APK,指定APK使用预签名的方式。Android.mk如下: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := DKTest LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_TAGS 阅读详情

相关推荐

手把手教你用WF100DPZ数字压力传感器搞定I2C/SPI通信(附完整寄存器解析)

本文详细解析了WF100DPZ数字压力传感器的I2C与SPI通信驱动方法,涵盖硬件连接、寄存器配置、数据读取流程及常见问题排查。该传感器内置24位ADC和出厂校准,通过实战代码演示了如何稳定获取高精度压力与温度数据,帮助开发者快速集成到嵌入式项目中。

weixin_28285943的博客 385

CodeForces 66A - Petya and Java(思维)

A. Petya and Java time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Little Petya has recently started attending a programming club. Naturall

Snakeflute的博客 576

别再对着数据手册发愁了!用HFSS 2023 R2搞定ESP32-C3板载天线的阻抗匹配

本文详细介绍了如何利用HFSS 2023 R2进行ESP32-C3板载天线的阻抗匹配优化,解决实际PCB设计中常见的性能偏差问题。通过智能模型导入、科学参数扫描和量化优化流程,显著提升天线性能,适用于WIFI和蓝牙应用场景。

weixin_42523543的博客 452

【CodeForces】[66A]Petya and Java

判断一个数的数据类型除了BigInteger之外其它的都可以直接判断 所以主要是判断是否是BigInteger 可根据位数 那么只需要判断位数与边界值位数相同的情况 其余的就是一些小技巧了

BoilTask Talk Show 695

DolphinScheduler租户配置踩坑实录:手把手教你修复‘tenant not exists‘报错

本文深度解析DolphinScheduler的租户模型,并提供一套从界面到数据库的系统性排查流程,手把手教你修复常见的'tenant not exists'报错。文章揭示了该错误的本质是用户与租户数据关联不一致,并给出了通过UI或SQL更新的具体修复方案,同时分享了根因分析与预防措施,帮助用户从根本上理解和避免此类问题。

2w3e4r5t6y的博客 544

R语言灰色关联分析法

输入数据并用DT包的datatable函数展示数据 ABDDEF分别对应第1到第6个供应商产品质量、技术水平、供应能力、经济效益、交货情况、市场影响度指标属于效益型指 产品价格、地理位置、售后服务指标属于成本型指标。现分别对上述指标进行规范化: 对于效益型指标(正项指标)标准化公式为: x∗=x−min(x)max(x)−min(x) x^{\ast}=\frac{x-min\left( x \right)}{max\left( x \right) -min\left( x \right)} x∗=max

qq_54423921的博客 8000

Codeforces 66A Petya and Java

Petya and Java 题意:五种数据类型,每种类型能存储的数据范围不同,占据的字节数也不同,求存储n可用的最少字节的数据类型。 思路:以字符串形式表示n,用函数strcmp进行比较。 #include #include #include using namespace std; int main(){ char a[105]; int len; scanf("%s",a);

渣渣眼里没有水题 465

GitHub与GitLab中的Fork操作:从个人仓库到团队协作的完整指南

本文详细介绍了GitHub与GitLab中的Fork操作,从个人仓库到团队协作的完整指南。通过Fork操作,开发者可以在权限隔离的环境下自由实验,并通过合并请求机制保证代码质量。文章涵盖了Fork的具体步骤、本地开发环境配置、代码同步方法以及高级协作技巧,帮助团队高效管理代码仓库。

weixin_28829325的博客 310

CodeForces 66A Petya and Java

A. Petya and Java time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Petya has recently started attendi

A_ice 593

RT-Thread与ROS2通信:micro-ROS在STM32上的移植实践

本文详细介绍了在STM32平台上使用RT-Thread实时操作系统移植micro-ROS实现与ROS2通信的实践方案。通过对比rosserial方案,重点阐述了micro-ROS基于XRCE-DDS协议栈在数据可靠性(丢包率低于1%)、双模式通信(UDP/串口)以及C/C++混合编程方面的优势,为嵌入式设备与ROS2的高效通信提供了完整解决方案。

emacs5lisp的博客 339

【技术科普】破解政务跨系统数据壁垒!亘川一网统管平台多源数据同步技术解析

本文解析亘川一网统管平台多源数据同步技术,针对政务跨系统数据壁垒难题,介绍组件的数据采集、校验、审计留痕等核心能力,结合营商环境项目落地案例,对比传统开发模式差异,讲解开源组件的实践价值,为政务项目开发者提供落地参考。

weixin_67440240的博客 642

(判断数字类型)C - Petya and Java CodeForces - 66A

C - Petya and Java CodeForces - 66A Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he ...

tomjobs的博客 518

系统安全性评估 (SSA) 详细解析

系统安全性评估(SSA)是一种自下而上的验证过程,目的是确保系统设计中的每个功能、子系统、硬件和软件的实现,符合早期通过 FHA 和 PSSA 设定的安全性需求。它通过对已实现的系统进行系统性综合评价,检验各项设计和安装是否符合预期的安全性目标,最终支持飞机的适航认证。飞行控制系统是飞机安全性设计的核心子系统之一,负责控制飞机的姿态和方向。为了确保飞行控制系统能够在各种飞行条件下保持安全运行,SSA 被用于验证该系统的设计是否满足 FHA 中设定的安全性目标。

qq_41854911的博客 1660

【Codeforces】66A - Petya and Java(模拟)

time limit per test  2 seconds memory limit per test  256 megabytes input  standard input output  standard output Little Petya has recently started attending a programming cl

wyg1997 924

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

CodeForces66APetya and Java

Description Little Petya has recently started attending a programming club. Naturally he is facing the problem of choosing a programming language. After long considerations he realized that Java is

菜鸟的自我修养 511

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

NYOJ:244 16进制的简单运算(c语言基础)

16进制的简单运算 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述现在给你一个16进制的加减法的表达式,要求用8进制输出表达式的结果。 输入第一行输入一个正整数T(0 接下来有T行,每行输入一个字符串s(长度小于15)字符串中有两个数和一个加号或者一个减号,且表达式合法并且所有运算的数都小于31位 输出每个表达式输出占一行,输出

zugofn的博客 5609

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

NYOJ:题目113 字符串替换

字符串替换 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述编写一个程序实现将字符串中的所有"you"替换成"we" 输入输入包含多行数据  每行数据是一个字符串,长度不超过1000  数据以EOF结束 输出对于输入的每一行,输出替换后的字符串 样例输入 you are what you do 样例输出 we a

zugofn的博客 4299

NYOJ:题目111 分数加减法

分数加减法 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述编写一个C程序,实现两个分数的加减法 输入输入包含多行数据  每行数据是一个字符串,格式是"a/boc/d"。  其中a, b, c, d是一个0-9的整数。o是运算符"+"或者"-"。  数据以EOF结束  输入数据保证合法 输出对于输入数据的每一行输出两个分

zugofn的博客 3354

HDU:5908 Abelian Period(水题+技巧)

Abelian Period    Accepts: 288    Submissions: 984  Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others) 问题描述 设SS是一个数字串,定义函数occ(S,x)occ(S,x)表示SS中数字xx的

zugofn的博客 1566

HDU:2073 无限的路(数学,水)

无限的路 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8089    Accepted Submission(s): 4197 Problem Description 甜甜从小就喜欢画图画,最近他买了一支智能画

zugofn的博客 1175

NYOJ:题目60 谁获得了最高奖学金

谁获得了最高奖学金 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述    某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同:   1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得;   2) 五四奖学金,每人4000元,期末平均成绩

zugofn的博客 1053

Light OJ:1136 Division by 3(规律)

1136 - Division by 3     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB There is sequence 1, 12, 123, 1234, ..., 12345678910, ... .

zugofn的博客 995

Codeforces 501B:Misha and Changing Handles(略水+小小技巧)

B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Misha hacked the Codeforces si

zugofn的博客 885

Codeforces 500A:New Year Transportation(水题)

A. New Year Transportation time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output New Year is coming in Line World

zugofn的博客 843

Codeforces 84A:Toy Army(水题)

Toy Army time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The hero of our story, Valera, and his best friend

zugofn的博客 790

Codeforces 300A:Array(易错)

A. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vitaly has an array of n distinct integers. Vitaly

zugofn的博客 779
上一篇: Light OJ:1328 A Gift from the Setter(数学)
下一篇: Codeforces 66B:Petya and Countryside(水题)
zugofn
博客等级 码龄11年 43粉丝 278原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值