Untitled
unknown
plain_text
3 years ago
955 B
11
Indexable
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int step = 2, i = 1, output_size = 0;
string spaces = "", new_spaces = "";
while(i <= n) {
string temp = spaces;
for(int j=0;j<step;j++, i++) {
if(i > n) break;
temp += to_string(i);
if(j != step-1 && i != n) temp += " ";
}
if(temp != "")cout<<temp<<'\n';
if(i > n) break;
int last_word = 0;
while(isdigit(temp[temp.size()-1-last_word])) last_word++;
// cout<<"last_word : "<<last_word<<'\n';
spaces = "";
for(int j=0;j<temp.size()-last_word;j++) spaces += ' ';
for(int j=0;j<step-2;j++, i++) {
if(i > n) break;
temp = spaces;
temp += to_string(i);
cout<<temp<<'\n';
}
step += 1;
// spaces = new_spaces;
}
return 0;
}
Editor is loading...