当前位置:网站首页>[ybtoj advanced training guidance] judgment overflow [error]
[ybtoj advanced training guidance] judgment overflow [error]
2022-07-02 12:32:00 【VL—MOESR】

Ideas :
Because it will exceed the boundary , Then transfer the form of multiplication to the form of division
( I originally wanted to practice with this problem c++ String input , The result didn't come out )
c o d e ( w r o n g ) code(wrong) code(wrong)
#include<iostream>
#include<cstdio>
using namespace std;
int t;
int main()
{
scanf("%d ", &t);
while(t--)
{
unsigned long long i;
string s="", ss="", s1="";
getline(cin, s1);
for(i=0; ; i++)
{
s=s+s1[i];
if(s=="int8"||
s=="unsigned int8"||
s=="int16"||
s=="unsigned int16"||
s=="int32"||
s=="unsigned int32"||
s=="int64"||
s=="unsigned int64")
break;
}
i+=2;
for(; i<s1.size(); i++)
ss=ss+s1[i];
unsigned long long maxx;
if(s=="int8")
maxx=127;
if(s=="unsigned int8")
maxx=255;
if(s=="int16")
maxx=32767;
if(s=="unsigned int16")
maxx=65535;
if(s=="int32")
maxx=2147483647;
if(s=="unsigned int32")
maxx=4294967295;
if(s=="int64")
maxx=9223372036854775807;
if(s=="unsigned int64")
maxx=18446744073709551615;
i=0;
unsigned long long sum=1, flag=1, j=0;
while(j<ss.size())
{
unsigned long long b=0;
for(; j<ss.size()&&ss[j]!=' '; j++)
b=b*10+ss[j]-48;
unsigned long long last=sum;
sum*=b;
i++;
if(sum>maxx||sum<0||sum/b!=last)
{
flag=0;
break;
}
j++;
}
if(flag==1)
printf("never\n");
else printf("%d\n", i);
}
return 0;
}
边栏推荐
- Leetcode739 daily temperature
- Drools executes string rules or executes a rule file
- 趣味 面试题
- FastDateFormat为什么线程安全
- Drools executes the specified rule
- PyTorch nn. Full analysis of RNN parameters
- drools中then部分的写法
- [C language] convert decimal numbers to binary numbers
- The differences and relationships among port, targetport, nodeport and containerport in kubenetes
- Sparkcontext: error initializing sparkcontext solution
猜你喜欢

drools决策表的简单使用

mysql表的增删改查(进阶)

CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节

The blink code based on Arduino and esp8266 runs successfully (including error analysis)

Lekao.com: experience sharing of junior economists and previous candidates in customs clearance

寻找二叉树中任意两个数的公共祖先

排序---

Simple understanding of ThreadLocal

Jenkins voucher management

CDH6之Sqoop添加数据库驱动
随机推荐
ThreadLocal的简单理解
Leetcode - Sword finger offer 51 Reverse pairs in an array
mysql索引和事务
Test shift left and right
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
mysql数据库基础
CV2 in OpenCV VideoWriter_ Fourcc() function and cv2 Combined use of videowriter() function
Leetcode209 长度最小的子数组
Openssh remote enumeration username vulnerability (cve-2018-15473)
字符串回文hash 模板题 O(1)判字符串是否回文
Leetcode122 买卖股票的最佳时机 II
Docker compose configuration mysql, redis, mongodb
Addition, deletion, modification and query of MySQL table (Advanced)
Drools dynamically add, modify, and delete rules
刷题---二叉树--2
lombok常用注解
Leetcode739 daily temperature
Is the neural network (pinn) with embedded physical knowledge a pit?
(C language) octal conversion decimal
Differences between nodes and sharding in ES cluster