1. 程式人生 > >讀入讀出掛

讀入讀出掛

span clas while pan || () put int getchar()

正數

 1 void re(int &x)
 2 {
 3     x=0;char s=getchar();
 4     while(s<0||s>9) s=getchar();
 5     while(s>=0&&s<=9){x=x*10+s-0;s=getchar();}
 6 }
 7 void wr(int x)
 8 {
 9     if(x>9) wr(x/10);
10     putchar(x%10+0);
11 }

正負

 1 void re(int &x)
 2 {
 3     int f=1
;x=0;char s=getchar(); 4 while(s<0||s>9){if(s==-)f=-1;s=getchar();} 5 while(s>=0&&s<=9){x=x*10+s-0;s=getchar();} 6 x*=f; 7 } 8 void wr(int x) 9 { 10 if(x<0){putchar-; x=-x;} 11 if(x>9)wr(x/10); 12 putchar(x%10+0); 13 }

完。

讀入讀出掛