当前位置:网站首页>Isosceles triangle - the 9th Lanqiao provincial competition - group C
Isosceles triangle - the 9th Lanqiao provincial competition - group C
2022-04-23 05:33:00 【Ice Cream~】
This topic requires you to output an isosceles triangle composed of numbers .
The specific steps are :
First use 1,2,3,… Spell a string long enough . Fill the three sides of the triangle with this string . Starting from the top vertex , Fill in counter clockwise . such as , When the height of the triangle is 8 when :
Input format :
A positive integer n, Represents the height of the triangle . 3<n<300
Output format :
Output , Isosceles triangles filled with numbers .
In order to facilitate evaluation , We require all spaces to be used . Instead of .
Specifically , Refer to the example .
sample input :
Here's a set of inputs . for example :
5
sample output :
Here is the corresponding output . for example :
....1 ...2.1 ..3...2 .4.....1 567891011
AC Code :
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
string s;
void shuzi(){ // First the 1~1500 The number of is stored in the string
for(int i=1;i<=1500;i++)
{
string s1="";
int a=i;
while(a)
{
s1+=(a%10+'0');
a/=10;
}
for(int k=s1.length()-1;k>=0;k--)
{
s+=s1[k];
}
}
}
int main()
{
shuzi();
int n;cin>>n;
int res=1;
int t=1;
for(int i=0;i<n-1;i++){
for(int j=1;j<=n-i-1;j++){ // Output the symbol before the first number of each line
cout<<".";
}
cout<<s[i];
if(i!=0){
for(int j=1;j<=2*i-1;j++){ // Output the number of symbols after the first number
cout<<".";
}
cout<<s[4*(n-1)-i]; // Find the law by counterclockwise circulation
}
cout<<endl;
}
for(int i=0;i<=2*(n-1);i++){ // Output the last line , from n Start
cout<<s[n+i-1];
}
return 0;
}
版权声明
本文为[Ice Cream~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220534524848.html
边栏推荐
猜你喜欢
The title bar will be pushed to coincide with the status bar
QT displays the specified position and size of the picture
Getting started with varnish
CPT 104_TTL 09
3d slicer中拉直体的生成
Redis的基本知识
Use of uniapp native plug-ins
How to set the initial value of El input number to null
相机成像+单应性变换+相机标定+立体校正
Uniapp wechat sharing
随机推荐
CPT 104_TTL 09
varnish入门
Frequently asked interview questions - 3 (operating system)
Parsing of string class intern() method
3d slicer中拉直体的生成
String class understanding - final is immutable
Relative reference and absolute reference of Excel
Use of qwbengneview and qwebchannel.
FileReader API file operation
Edit, cancel, pull up menu
STL learning notes 0x0001 (container classification)
Deep learning object detection
The QT debug version runs normally and the release version runs crash
World and personal development
Parameter analysis of open3d material setting
跨域CORS的情缘~
Write the declaration of a function to return the reference of the array, and the array contains 10 string objects (notes)
世界与个人发展
STL function library
Use of ES6 array