码迷,mamicode.com
首页 > 其他好文 > 详细

快速输入输出大综合

时间:2016-07-19 16:56:07      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

int 类型的数字的快速输入输出大综合:-)

#include<iostream>
using namespace std;
void write(int x)
{
    if(x==0)
    {
        putchar(0);
        return ;
    }
    if(x<0)
    {
        putchar(-);
        x=-x;
    }
    int len=0,buf[15];
    while(x)
    {
        buf[len++]=x%10;
        x/=10;
    }
    for(int i=len-1;i>=0;i--)putchar(buf[i]+0);
    return ;
}
int read()
{
    int 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;
}
int main()
{
    int a=read();
    write(a);
    system("pause");
    return 0;
}

 

快速输入输出大综合

标签:

原文地址:http://www.cnblogs.com/ysmor/p/5685346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!