Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. /*Scrivere un metodo che prende in input una matrice quadrata A di n x n puntatori a stringhe, e
  2. restituisca un puntatore ad una stringa ottenuta concatenando tutti i caratteri centrali delle stringhe
  3. di lunghezza dispari presenti nella diagonale secondaria di A.*/
  4.  
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace std ;
  9.  
  10. void punt () ;
  11.  
  12. int main (){
  13.  
  14. punt () ;
  15.  
  16. }
  17.  
  18. void punt (){
  19.  
  20. int n ;
  21.  
  22. cout<< " Inserisci la dimensione della matrice : " ;
  23.  
  24. cin >> n ;
  25.  
  26. cout<<endl ;
  27.  
  28. string A[n][n] ;
  29.  
  30. string *c = &A[0][0] ;
  31.  
  32. for ( int x = 0 ; x < n*n ; x++ ){
  33.  
  34. cout<< " Inserisci la stringa in posizione ("<<x<<") = " ;
  35.  
  36. cin>> *c++ ;
  37.  
  38. }
  39.  
  40. cout<<endl ;
  41.  
  42. int pedice, k = 0 ;
  43.  
  44. string ottenuta (" ", n) ;
  45.  
  46. string *p = &ottenuta ;
  47.  
  48. char box ;
  49.  
  50. for ( int x = 0, y = 0 ; x < n, y < n ; x++, y++){
  51.  
  52. if ( A[x][y].length() % 2 == 1 ){
  53.  
  54. pedice = A[x][y].length() / 2 ;
  55.  
  56. box = A[x][y].at(perice) ;
  57.  
  58. ottenuta.at(k) = box ;
  59.  
  60. k++ ;
  61.  
  62. }
  63.  
  64. }
  65.  
  66. cout<< " La stringa ottenuta mediante la concatenazione di tutti i caratteri centrali e' : "<<* p<<endl ;
  67. system("pause") ;
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement