#54531: 最強IOI優化輸入/輸出整數


kita197 (KK)


#include<stdio.h>
#ifdef _WIN32          //Windows要用的東西
    #define getchar_unlocked _getchar_nolock
    #define putchar_unlocked _putchar_nolock
#endif
inline int readUInt(){
    int x=0;
    char c=getchar_unlocked();
    while(c&&(c<'0'||c>'9'))c=getchar_unlocked();           //一行輸入多個就自己想吧
    if(c==EOF)return-1;
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+(c-'0');
        c=getchar_unlocked();
    }
    return x;
}
inline void writeInt(int x){
    if(!x){
        putchar_unlocked('0');
        return;
    }
    static char s[12];
    int len=0;
    while(x){
        s[len++]=(x%10)+'0';
        x/=10;
    }
    while(len--)putchar_unlocked(s[len]);
}

#54532: Re: 最強IOI優化輸入/輸出整數


kita197 (KK)


標題不小心多打一個字

 

輸入只能輸入正整數

#54533: Re: 最強IOI優化輸入/輸出整數


kita197 (KK)


#include<cstdio>
#include<stdbool.h>
#ifdef _WIN32
    #define getchar_unlocked _getchar_nolock
    #define putchar_unlocked _putchar_nolock
#endif
inline int readInt(){      //yee!!!可以輸入負數了
    int x=0;
    bool negative=0;
    char c=getchar_unlocked();
    while(!c&&(c<'0'||c>'9'||c!='-'))c=getchar_unlocked(); //少打一個'!'
    if(c==EOF)return-1;
    while((c>='0'&&c<='9')||(c=='-')){
        if(c=='-')negative=!negative;
        x=(x<<3)+(x<<1)+(c-'0');
        c=getchar_unlocked();
    }
    return(negative?(~x+1):(x));
}
inline void writeInt(int x){
    if(!x){
        putchar_unlocked('0');
        return;
    }
    if(x<0)putchar_unlocked('-');
    static char s[12];
    int len=0;
    while(x){
        s[len++]=(x%10)+'0';
        x/=10;
    }
    while(len--)putchar_unlocked(s[len]);
}