Create a crossword C ++ [closed]

0

Who could help me with this?

I'll put an example of what I want.

A     A
 R   R
  M M
   A
  N N
 D   D
O     O

But the same spaces have to be horizontal, as in the vertical, have to be squared.

Thank you

    
asked by anonymous 24.10.2015 / 18:11

2 answers

3

Is this good?

#include <iostream>
#include <string>
using namespace std;

int main() {
    const string c = "ARMANDO";
    int t = c.length() - 1;
    for (int i = 0; i <= t; i++) {
        for (int j = 0; j <= t; j++) {
            cout << (i == j || i == t - j ? c[i] : ' ');
        }
        cout << '\n';
    }
}

The trick is that i == j is the main diagonal and i == t - j is the secondary diagonal.

    
25.10.2015 / 06:11
1

I, yesterday after a lot of fighting I succeeded.

I want to thank everyone who helped and gave me ideas.

Thank you.

I leave the resolution here.

#include <iostream>
#include <string>

using namespace std;

int main(){
    cout << "Introduza nome: ";
    string name;
    getline(cin, name);


    for(int line = 0; line < name.size(); line++){
        for(int space=0; space < name.size();space++){
            if(space == line){
                cout << name[line];
            }
            else{
                if(space == name.size()-line-1){
                    cout << name[line];
                }
                else{
                    cout << " ";
                }
            }
        }   
        cout << endl;
    }
    return 0;
}

    
25.10.2015 / 10:39