1. 程式人生 > >輸入輸出外掛

輸入輸出外掛

僅適合純數字

程式碼:


/* 僅適合純數字輸入輸出 */
#include <cstdio>
 
int Scan() {    //輸入外掛
    int res = 0, flag = 0;
    char ch;
    while((ch=getchar()),ch != '-'&&(ch< '0'||ch>'9'));
    if(ch=='-') flag = 1;
    else res = ch - '0';
    while((ch = getchar()) >= '0' && ch <= '9')
        res = res * 10 + (ch - '0');
    return flag ? -res : res;
}
 
void Out(int a) {    //輸出外掛
    if(a < 0) { putchar('-'); a = -a; }
    if(a >= 10) Out(a / 10);
    putchar(a % 10 + '0');
}
 
int main() {
    int T, n;
    scanf("%d", &T);
    while(T--) {
        n = Scan();
        Out(n);
        printf("\n");
    }
    return 0;
}