当前位置:网站首页>[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;
}
边栏推荐
- 倍增 LCA(最近公共祖先)
- On data preprocessing in sklearn
- Addition, deletion, modification and query of MySQL table (Advanced)
- WSL 2 will not be installed yet? It's enough to read this article
- Find the common ancestor of any two numbers in a binary tree
- LeetCode—剑指 Offer 59 - I、59 - II
- 防抖 节流
- Interview with meituan, a 34 year old programmer, was rejected: only those under the age of 30 who work hard and earn little overtime
- 怎样写一篇赏心悦目的英文数学论文
- BOM DOM
猜你喜欢
随机推荐
Leetcode - < dynamic planning special> Jianzhi offer 19, 49, 60
AI mid stage technology research
The most understandable f-string tutorial in history, collecting this one is enough
Simple use of drools decision table
Record the range of data that MySQL update will lock
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
Full link voltage measurement
二分刷题记录(洛谷题单)区间的甄别
CDA data analysis -- Introduction and use of aarrr growth model
H5 to app
Thesis translation: 2022_ PACDNN: A phase-aware composite deep neural network for speech enhancement
Drools terminates the execution of other rules after executing one rule
Input a three digit number and output its single digit, ten digit and hundred digit.
Leetcode209 长度最小的子数组
Find the common ancestor of any two numbers in a binary tree
Leetcode - Sword finger offer 51 Reverse pairs in an array
Docker compose configuration mysql, redis, mongodb
Mysql database foundation
lombok常用注解
MySQL与PostgreSQL抓取慢sql的方法






![[C language] convert decimal numbers to binary numbers](/img/9b/1848b68b95d98389ed985c83f2e856.png)

