Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Scrivere un metodo che prende in input una matrice quadrata A di n x n puntatori a stringhe, e
- restituisca un puntatore ad una stringa ottenuta concatenando tutti i caratteri centrali delle stringhe
- di lunghezza dispari presenti nella diagonale secondaria di A.*/
- #include <iostream>
- #include <string>
- using namespace std ;
- void punt () ;
- int main (){
- punt () ;
- }
- void punt (){
- int n ;
- cout<< " Inserisci la dimensione della matrice : " ;
- cin >> n ;
- cout<<endl ;
- string A[n][n] ;
- string *c = &A[0][0] ;
- for ( int x = 0 ; x < n*n ; x++ ){
- cout<< " Inserisci la stringa in posizione ("<<x<<") = " ;
- cin>> *c++ ;
- }
- cout<<endl ;
- int pedice, k = 0 ;
- string ottenuta (" ", n) ;
- string *p = &ottenuta ;
- char box ;
- for ( int x = 0, y = 0 ; x < n, y < n ; x++, y++){
- if ( A[x][y].length() % 2 == 1 ){
- pedice = A[x][y].length() / 2 ;
- box = A[x][y].at(perice) ;
- ottenuta.at(k) = box ;
- k++ ;
- }
- }
- cout<< " La stringa ottenuta mediante la concatenazione di tutti i caratteri centrali e' : "<<* p<<endl ;
- system("pause") ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement