tonfain

TonfaiGeneratingTriangles

Dec 28th, 2023
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     ifstream fin("generatingtriangles.in");
  6.    
  7.     int N, S;
  8.     fin >> N >> S;
  9.    
  10.     vector<vector<int>> temp_tri(N);
  11.     int curr_num = S;
  12.     for(int i = 0; i<N; i++){
  13.         for(int j = 0; j<i+1; j++){
  14.             //cout << "i: " << i << endl;
  15.             temp_tri[i].push_back(curr_num);
  16.             curr_num++;
  17.             if(curr_num > 9){
  18.                 curr_num = 1;
  19.             }
  20.         }
  21.     }
  22.     //cout << temp_tri[1][0] << endl;
  23.     //cout << temp_tri[0][0] << " " << temp_tri[1][0] << temp_tri[2][0] << " " << temp_tri[3][0] << " " << temp_tri[4][0] << endl;
  24.     for(int i = 0; i<N; i++){
  25.         for(int j = 0; j<i; j++){
  26.             cout << " " << " ";
  27.         }
  28.         for(int j = i; j<N-1; j++){
  29.             cout << temp_tri[j][i] << " ";
  30.         }
  31.         cout << temp_tri[N-1][i] << endl;
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment