刷题记录:牛客NC22208数字三角形

传送门:牛客

题目描述:

打印数字三角形,从1开始输出,第i行输出i个数,每个数字按4个位置输出
注:c语言中 %4d可以输出一个数,占据四个位置,右对齐。
输入:
4
输出:
   1
   2   3
   4   5   6
   7   8   9  10

emmm,我不知道这道题为什么被放在了dp的题单里,这道题应该是一道语法题啊

思路没什么好说的,直接照搬即可.本来不想打这篇题解的,为了完整性还是打了

具体的代码部分:

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {
	ll x=0,w=1;char ch=getchar();
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*w;
}
#define maxn 1000000
#define ll_maxn 0x3f3f3f3f3f3f3f3f
const double eps=1e-8;
int n;int t=1;
int main() {
	n=read();
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=i;j++) {
			printf("%4d",t);
			t++;
		}
		printf("\n");
	}
	return 0;
}

你可能感兴趣的:(c++算法,c++,算法,图论)