当前位置:网站首页>[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;
}
边栏推荐
- WSL 2 will not be installed yet? It's enough to read this article
- Test shift left and right
- Leetcode122 the best time to buy and sell stocks II
- Differences between nodes and sharding in ES cluster
- Find the common ancestor of any two numbers in a binary tree
- Tas (file d'attente prioritaire)
- CPU指令集介绍
- lombok常用注解
- Jenkins voucher management
- CV2 in OpenCV VideoWriter_ Fourcc() function and cv2 Combined use of videowriter() function
猜你喜欢
堆(优先级队列)
jenkins 凭证管理
Test shift left and right
Embedded Software Engineer career planning
寻找二叉树中任意两个数的公共祖先
甜心教主:王心凌
"As a junior college student, I found out how difficult it is to counter attack after graduation."
The blink code based on Arduino and esp8266 runs successfully (including error analysis)
初始JDBC 编程
Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
随机推荐
post请求体内容无法重复获取
OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
Sweetheart leader: Wang Xinling
Post request body content cannot be retrieved repeatedly
Performance tuning project case
Test shift left and right
The differences and relationships among port, targetport, nodeport and containerport in kubenetes
堆(優先級隊列)
Day12 control flow if switch while do While guessing numbers game
中国交通标志检测数据集
考研英语二大作文模板/图表作文,英语图表作文这一篇就够了
jenkins 凭证管理
Mysql database foundation
5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
Those logs in MySQL
FastDateFormat为什么线程安全
Error in kubeadm join: [error port-10250]: port 10250 is in use [error fileavailable--etc kubernetes PKI
Leetcode209 长度最小的子数组
Differences between nodes and sharding in ES cluster
Multiply LCA (nearest common ancestor)