#ifndef _GLIBCXX_read
#define _GLIBCXX_read 1
#progma GCC system_header
#include <cstdio>
namespace std _GLIBCXX_VISIBILITY(default){
_GLIBCXX_BEGIN_NAMESPACE_VERSION
void pushint(int &index,int pushindex){
index*=10;
index+=pushindex;
}
template<typename intype>
intype readint(){
char c;
bool fs=false;
c=getchar();
intype finally=0;
if(c=='-'){
fs=true;
}
else{
if(c<'0'||c>'9'){
return finally;
}
else{
push(finally,c-'0');
}
}
while(1){
c=getchar();
if(c<'0'||c>'9'){
break;
}
else{
push(finally,c-'0');
}
}
return (fs?(0-finally):finally);
}
#define readchar getchar()
_GLIBCXX_END_NAMESPACE_VERSION
}
#endif
將以上代碼保存為read.h,使用時只需#include "read.h"即可(注意:一定要在相同目錄下!!!)
支持讀入整數int x=readint<int>(); or long long x=readint<long long>(); or long x=readint<long>(); or short x=readint<short>();
如果要提交題目怎么辦??
答:取出你要用的部分即可,
讀入整數:
void pushint(int &index,int pushindex){
index*=10;
index+=pushindex;
}
template<typename intype>
intype readint(){
char c;
bool fs=false;
c=getchar();
intype finally=0;
if(c=='-'){
fs=true;
}
else{
if(c<'0'||c>'9'){
return finally;
}
else{
push(finally,c-'0');
}
}
while(1){
c=getchar();
if(c<'0'||c>'9'){
break;
}
else{
push(finally,c-'0');
}
}
return (fs?(0-finally):finally);
}
讀入字符:
#define readchar getchar
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/33456.html
標籤:C++
下一篇:虛函式實作多型性 代碼參考
