其他分享
首页 > 其他分享> > Stringstream

Stringstream

作者:互联网

Stringstream

Digits Sequence (Easy Edition)

#include<bits/stdc++.h>//Forever_chen
#define RT register
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f)x=-x;return x;
}
template<class t>inline void write(t x){
	if(x<0)putchar('-'),write(-x);
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}
template<class t>inline void writeln(t x){
	write(x);putchar('\n');
	return;
}
template<class t>inline void write_blank(t x){
	write(x);putchar(' ');
	return;
}
int n,k;
stringstream s; //定义一个stringstream类型的s
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(int i=1;s.str().size()<=n;i++){//取长,和string类型相类似
		s<<i;//将int类型的i压入s
	}
	cout<<s.str()[n-1];//输出第n-1项
	//system("pause");
	return 0;
}

标签:putchar,int,void,Stringstream,write,这道题,stringstream
来源: https://www.cnblogs.com/Forever-chen/p/12866971.html