Petya and Java strcmp的使用

java中文编码实现C++的strcmp功能 由于现在java和c++跨平台移植的情况多,所以保持一些原有的基本的工作操作,自己就在很多移植中发现了一些较为痛苦的事情,所以不得去研究两个平台的编码问题。   中文编码在c++和java中就有一定的差距,比如说在C++中用strcmp(const char *s1,const char * s2)比较中文时,在java中没有相对应的函数,其中在java中的String.CompareTo(O 阅读详情


Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64u


Description

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

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

Petya knows only 5 integer types:

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

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

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

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

5) BigInteger can storeany integer number, but at that it is not a primitive type, andoperations with it are much slower.

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

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

Input

The first line contains a positivenumber n. It consists of no morethan 100 digits and doesn'tcontain any leading zeros. The number n can't berepresented as an empty string.

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

Output

Print the first type from the list "byte, short, int, long, BigInteger", that can store the naturalnumber n, in accordance with the datagiven above.

Sample Input

Input
127

Output
byte

Input
130

Output
short

Input
123456789101112131415161718192021222324

Output
BigInteger
以前没真正弄明白函数strcmp的具体用途,以为只能比较字符,原来比较字符就是比较ASCLL码,!!也就是可以比较数字大小(当然是在位数同样的前提下),这样的话,先判断
位数在进行比较,这题就AC了!
#include<iostream>
using namespace std;
int main()
{     int l;
char c[105];
while(scanf("%s",c)!=EOF)
{
        l=strlen(c);
        if(l<3||l==3&&strcmp(c,"127")<=0) 
                cout<<"byte"<<endl;
        else 
                if(l<5||l==5&&strcmp(c,"32767")<=0)
                        cout<<"short"<<endl;
                else
                        if(l<10||l==10&&strcmp(c,"2147483647")<=0)
                                cout<<"int"<<endl; 
                        else
                        if(l<19||l==19&&strcmp(c,"9223372036854775807")<=0)
                                        cout<<"long"<<endl;
                                else
                                        cout<<"BigInteger"<<endl;                          
}
return 0;
}


java实现strcmp函数功能(附完整源码) 阅读详情

相关推荐

HACK RF学习之旅记录1——填坑历程

在家隔离期偶尔发现RTL SDR,是realtek芯片破解了做软件无线电,价格非常实在不到百元,功能可以玩电视 广播等等。后来搜搜发现更强大的Hack RF ONE开发板,淘宝和闲鱼都看了大多都是Hack RF ONE单板999,便宜的闲鱼有600多的。还有一块扩展板是MCU+屏+时钟,看起来也很实用(非常推荐)。通过闲鱼某卖家找了渠道,从上海一家店的淘宝下单优惠价格(据说是原厂,超出想象,暗号是...

ZForce2009的博客 1万+

Java语言strcmp函数用法_蓝桥杯 算法提高 11-1实现strcmp函数 (JAVA方法)

蓝桥杯 算法提高 11-1实现strcmp函数 (JAVA方法)首先这不是一个多难的题,但是网上的我没怎么找到有Java的代码,基本全都是c语言的,小编是个小白,如果有不对的地方请联系小编问题描述自己实现一个比较字符串大小的函数,也即实现strcmp函数。函数:int myStrcmp(char *s1,char *s2) 按照ASCII顺序比较字符串s1与s2。若s1与s2相等返回0,s1&g...

weixin_33794626的博客 1028

黑马Java第二阶段:JavaWeb(笔记)

黑马Java第二阶段:JavaWeb(笔记)

chen的博客 5681

strcmp java_(一)strcmp函数

(一)strcmp函数strcmp函数是比较两个字符串的大小,返回比较的结果。一般形式是:i=strcmp(字符串,字符串);其中,字符串1、字符串2均可为字符串常量或变量;i 是用于存放比较结果的整型变量。比较结果是这样规定的:①字符串1小于字符串2,strcmp函数返回一个负值;②字符串1等于字符串2,strcmp函数返回零;③字符串1大于字符串2,strcmp函数返回一个正值;那么,字符...

weixin_42499201的博客 3251

MOSFET开关损耗全面讲解:从原理到优化策略

深入剖析MOSFET开关损耗的产生机制,结合实际应用场景,讲解如何通过驱动设计和电路优化降低损耗,提升系统效率。重点关注mosfet在高频开关下的表现与热管理。

weixin_29476595的博客 1065

非易失存储器读写

24C256、IIC_SCL、IIC_SDA

CT_1104的专栏 2991

java版 strcmp函数

private static boolean strcmp( Message msg ) { if( msg == null ){             // No message indicates that the message queue is quitting.             return false;         } if( msg.target.getCla

dp__mcu的专栏 3138

等保三级-MySQL 安全加固实战指南

本文详细介绍了MySQL数据库在等保三级要求下的安全加固实战指南,涵盖身份鉴别、访问控制、安全审计、网络传输安全、入侵防范和数据完整性等关键领域。通过具体配置示例和实战经验,帮助用户有效提升MySQL数据库的安全防护能力,满足等保三级合规要求。

weixin_29197835的博客 188

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.

无知的我 1955

keras tensorflow 的lstm的新冠疫情感染人数预测 附完整代码数据 可直接运行

keras tensorflow 的lstm的新冠疫情感染人数预测 附完整代码数据 可直接运行

853

微信小程序 - 实现仿小红书轮播图组件功能,类似小红书笔记页面图片展示播放效果,微信小程序仿小红书幻灯片轮播支持视频播放、图片预览,自动适应图片或视频大小可左右滑动切换(小程序精美轮播图,丝滑切换)

微信小程序,轮播图组件,微信小程序仿小红书轮播图,小红书轮播图仿造,微信小程序轮播图,微信小程序幻灯片,微信小程序高仿小红书轮播图实现,小程序实现类似小红书一样的轮播图组件,轮播图插件,精致轮播图,精美丝滑流畅切换的轮播图,轮播图组件,小红薯轮播图,关于小红书的小程序不同数量的轮播图,展示不一样的轮播指示点的实现,微信小程序仿小红书图片轮播,开发微信小程序模仿小红书,高仿小红书Banner的指示器,小红书小程序笔记详情轮播图指示点的随图片数量的变化动态变化,微信小程序swiper轮播图,js轮播图,html

✅ 精选推荐文章 6936

java strcmp_strcmp函数和strcpy函数

(一)strcmp函数strcmp函数是比較两个字符串的大小,返回比較的结果。一般形式是:i=strcmp(字符串,字符串);当中,字符串1、字符串2均可为字符串常量或变量;i 是用于存放比較结果的整型变量。比較结果是这样规定的:①字符串1小于字符串2,strcmp函数返回一个负值;②字符串1等于字符串2,strcmp函数返回零;③字符串1大于字符串2,strcmp函数返回一个正值;那么,字符...

weixin_39538687的博客 433

灰色预测GM(1,n)模型_python

灰色系统理论及其应用系列博文: 一、灰色关联度分析法(GRA)_python 二、灰色预测模型GM(1,1) 文章目录一、GM(1,n)算法二、示例2.1 数据:2.2 代码_使用GM(1,n)城市用水总量2.3 结果分析 一、GM(1,n)算法 二、示例 注:数据均来自论文《基于灰色系统理论的贵阳市城市用水总量预测》 2.1 数据: data.csv 年份,城区人口,建成区面积,供水总量,用水人口,人口综合用水指标,城市用水总量 2002, 191.85, 98.00, 26396.00,

qq_34229228的博客 1万+

Petya and Java strcmp的使用

B - Petya and Java Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description Little Petya has recently started attending a programming club. Na

qq_34472846的博客 649

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Java语言strcmp函数用法_Petya and Java strcmp的使用

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

weixin_39638305的博客 270

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

CodeForces Petya and Java strcmp的使用

B - Petya and JavaTime Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u DescriptionLittle Petya has recently started attending a programming club. Naturally he is facing t...

weixin_30470857的博客 67

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...

【CodeForces】[66A]Petya and Java

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

BoilTask Talk Show 695

CodeForce 66A Petya and Java

A - Petya and Java Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Little Petya has recently started attending a programming clu

Calm微笑 580

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

算法提高 11-1实现strcmp函数 java版

问题描述   自己实现一个比较字符串大小的函数,也即实现strcmp函数。函数:int myStrcmp(char *s1,char *s2) 按照ASCII顺序比较字符串s1与s2。若s1与s2相等返回0,s1>s2返回1,s1   "A"   "a">"A"   "computer">"compare"   "hello" 样例输出 数据规模和约定   字符串长度

你就是根号四的博客 1221

实现strcmp函数

import java.util.Scanner;   public class Main { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); String s1 = scanner.next(); String s2 = scanner.next(); char ch1[...

平行宇宙i的博客 534

​C语言strcmp()函数:比较字符串(区分大小写)

头文件:#include strcmp() 用来比较字符串(区分大小写),其原型为:     int strcmp(const char *s1, const char *s2); 【参数】s1, s2 为需要比较的两个字符串。 字符串大小的比较是以ASCII 码表上的顺序来决定,此顺序亦为字符的值。strcmp()首先将s1 第一个字符值减去s2 第一个字符值,若差值为0

雁峰 3141

Petya and Java(整型类型)

Petya and Java Time Limit:2000MS    Memory Limit:262144KB     64bit IO Format:%I64d& %I64u Submit Status Description Little Petya has recently started attending a programming club. Naturally

昨日明眸 599

关于strcmp函数的用法

strcmp函数是在string.h库下的han函数, 具体用法如下: strcmp函数是用来比较2个字符串的函数,如srcmp(字如果符串1,字符串2),从第一个字符开始比较,如果到最后两个字符串完全相同,则strcmp()函数输出的值为0;若开始出现不同的字符,根据这个字符ASCII码进行比较,若字符串1的ASSCII值大于2 则输出值 大于 0;反之,输出值 小于 0;...

black_hole6的博客 3万+

蓝桥杯-11-1实现strcmp函数(java)

算法提高 11-1实现strcmp函数 时间限制:1.0s 内存限制:256.0MB 问题描述   自己实现一个比较字符串大小的函数,也即实现strcmp函数。函数:int myStrcmp(char *s1,char *s2) 按照ASCII顺序比较字符串s1与s2。若s1与s2相...

好好学java 552
上一篇: poj 1595
下一篇: C++ string 详解
onlinewk
博客等级 码龄16年 2粉丝 96原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值