输入外挂(int,long long,float,double)

发布于 2018-03-06  850 次阅读


代码

#include 
#include 
using namespace std;

template 
bool scan_d(T &ret)
{
    char c; 
    int sgn; 
    T bit = 0.1;
    if (c=getchar(), c==EOF) 
    {
        return 0;
    }
    while (c != '-' && c != '.' && (c < '0' || c > '9')) 
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    if (c == ' ' || c == '\n')
    {
        ret *= sgn;
        return 1;
    }
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret += (c - '0') * bit, bit /= 10;
    }
    ret *= sgn;
    return 1;
}

int main()
{
	double a;
	int b;
	scan_d(a); 
	scan_d(b);
	cout << a << endl << b << endl;
}