读入读出挂

正数

 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 }

 

完。

posted @ 2018-10-01 18:15  RedBlack  阅读(230)  评论(0编辑  收藏  举报