(转载)C++中如何使用大整数__int128

转自:https://blog.csdn.net/shadandeajian/article/details/81843805

据说,__int128只能在linux环境下才能编译成功,不过大部分OJ都是用linux为后台,所以掌握__int128还是很重要的

__int128的输入输出模板

#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;
}

inline void print(__int128 x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)
        print(x/10);
    putchar(x%10+'0');
}

int main(void){
    __int128 a = read();
    __int128 b = read();
    print(a + b);
    cout<

 

你可能感兴趣的:(模板)