C++输入挂

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dllpXFire/article/details/81183549

普通输入挂(来自cbc)

#include <bits/stdc++.h>
using namespace std;

template <class T>
inline void _cin1(T &ret) 		//读正整数 (int, long long)
{
    char c;
    ret = 0;
    while((c = getchar()) < '0' || c > '9');
    while(c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
        c = getchar();
    }
}

template <class T>
inline bool _cin2(T &ret) 		//读正整数并判断文件结束 (int, long long)
{
    char ch;
    if(ch = getchar(), ch == EOF) return 0;
    while(ch < '0' || ch > '9') ch = getchar();
    for(ret = 0; ch >= '0' && ch <= '9'; ch = getchar())
    	ret = ret * 10 + ch - '0';
    return 1;
}

template <class T>
inline void _cin3(T &ret)		//读正负整数 (int, long long)
{
    char ch;
    int flag = 0;
    while((ch = getchar()) < '0' || ch > '9')
    {
        if(ch == '-') flag = 1;
    }
    for(ret = 0; ch >= '0' && ch <= '9'; ch = getchar())
    	ret = ret * 10 + ch - '0';
    if(flag) ret *= -1;
}

template <class T>
inline bool _cin4(T &ret)		//读正负整数且判断文件结束 (ing, long long)
{
    char ch;
    int flag = 0;
    if(ch = getchar(), ch == EOF) return 0;
    while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
    if(ch == '-')
    {
    	flag = 1;
    	ch = getchar();
    }
    for(ret = 0; ch >= '0' && ch <= '9'; ch = getchar())
    	ret = ret * 10 + ch - '0';
    if(flag) ret *= -1;
    return 1;
}

template <class T>
void _cout(T ret)				//输出外挂 (int, long long)
{
    if(ret < 0)
    {
        putchar('-');
        ret = -ret;
    }
    if(ret > 9) _cout(ret/10);
    putchar(ret%10 + '0');
}

template <class T>
inline bool _scanf(T &ret)		//读入整数浮点数并判断文件结束 (int, long long, float, double)
{
    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()
{
	long long n;
	_cin1(n);
	cout << n << endl;

	while(_cin2(n)) cout << n << endl;

	_cin3(n);
	cout << n << endl;

	while(_cin4(n)) cout << n << endl;

	cin >> n;
	_cout(n);

	double f;
	_scanf(n); printf("%lld\n", n);
	_scanf(f); printf("%.3f\n", f);
	return 0;
}

最强输入挂(只限读入正整数)

/*
    需要freopen文件输入输出来测试样例答案,否则用命令行输入不会返回结果,交题时记得注释掉freopen
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
namespace fastIO {
	#define BUF_SIZE 100000
	//fread -> read
	bool IOerror = 0;
	inline char nc() {
		static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
		if(p1 == pend) {
			p1 = buf;
			pend = buf + fread(buf, 1, BUF_SIZE, stdin);
			if(pend == p1) {
				IOerror = 1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch) {
		return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
	}
	inline void read(int &x) {
		char ch;
		while(blank(ch = nc()));
		if(IOerror)
			return;
		for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
	}
	#undef BUF_SIZE
};
using namespace fastIO;
const int maxn = 1000001, mod = 1000000007;
int n, num[maxn];
int main()
{
	for(int Case = 1; read(n), !fastIO::IOerror; ++Case)
	{
		for(int i = 1; i <= n; ++i)
			read(num[i]);
	}
	return 0;
}

 

展开阅读全文

没有更多推荐了,返回首页