题目来源:
https://vjudge.net/contest/290636#problem/H
https://ac.2333.moe/Problem/view.xhtml?id=1226
题目描述:
In this problem you need to make a triangle ,just like the sample out. The element in the ith row and jth column
should be the product(乘积) of i and j.
Input
The first line of input is an integer C which indicate the number of test cases.
Then C test cases follow.Each test case contains an integer N (1<=N<=20) in a line which mentioned above.
Output
For each test case, print out the triangle. the triangle separated by a blank line.
If the product is more than 9 (product > 9) you should print a space, or you should print two space.The final number of each line don't need print space.
Sample Input
3 5 6 7
Sample Output
1 2 3 4 5 2 4 6 8 3 6 9 4 8 5 1 2 3 4 5 6 2 4 6 8 10 3 6 9 12 4 8 12 5 10 6 1 2 3 4 5 6 7 2 4 6 8 10 12 3 6 9 12 15 4 8 12 16 5 10 15 6 12 7
Hint
无
思路:没有思路,水题,因为没有看清题目描述,就一直PE,QAQ
参考代码:
#include<iostream>
using namespace std;
int main()
{
int t,n;
while(cin>>t)
{
while(t--)
{
cin>>n;
for(int i = 1; i<=n; i++)
{
int t=0;
for(int j=i; t<(n-i+1); j+=i)
{
t++;
if(j==i)
cout<<j;
else
{
if((j>9)&&(j-i>9))
cout<<" "<<j;
else
cout<<" "<<j;
}
}
cout<<endl;
}
if(t)cout<<endl;
}
}
return 0;
}