__int128的使用

前天打牛客,一个大数题,大佬用__int128轻松过,感觉特别神奇,自己就去搜,学一学!
传送门:https://ac.nowcoder.com/acm/contest/881/J

> #include using namespace std; long long a,b,x,y; int main(){
>     while (scanf("%lld%lld%lld%lld",&x,&a,&y,&b)==4){
>         __int128 p=x; p=p*b;
>         __int128 q=y; q=q*a;
>         if (p         else if (p>q) puts(">");
>         else puts("=");
>     }
>     return 0; }

__int128 在CB 16.01 /DEV C++中是无法编译,但是在oj上可以用,是不是很神奇!

通过在博客园中Angel_Kitty的博客学习后,我就去找了些题来实现下:

例如:https://www.nowcoder.com/acm/contest/211/A

AC代码:

>   #include  using namespace std; inline __int128
> read(){
>     __int128 x=0,f=1;
>     char ch=getchar();
>     while(ch<'0'||ch>'9'){
>         if(ch=='-')
>             f=-1;
>         ch=getchar();
>     }
>     while(ch>='0'&&ch<='9'){
>         x=x*10+ch-'0';
>         ch=getchar();
>     }
>     return x*f; } int main() {
>     __int128 s = 0;   int n,x;  
>        scanf("%d",&n);
>         for(int i=1;i<=n;i++)
>     {
>         scanf("%d",&x);
>         if(x>=0)
>            s+=x; 
>         else 
>             s+=1LL*x*i;
>     }
>     if(s<0)
>         {
>             s=-s;
>             printf("-");
>         }
>     print(s);
>     return 0; }

__int128 a = read();
__int128 b = read();
print(a + b);

你可能感兴趣的:(ACM)