Advertisement
gilbertoavpereira

APROG - 21/01/2013 - Exame Época Normal - Grupo II

Jan 29th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class II21012013 {
  4.    
  5.     private static Scanner in= new Scanner(System.in);
  6.    
  7.     public static int[][] criarMatriz(int n,int m){
  8.         int[][] mat=new int[n][m];
  9.         for(int i=0;i<n;i++){
  10.             for(int j=0;j<m;j++){
  11.                 System.out.print("MAT["+i+"]["+j+"]=");
  12.                 mat[i][j]=in.nextInt();
  13.             }
  14.         }
  15.         return mat;
  16.     }
  17.    
  18.     public static void mostarMatiz(int[][] m){
  19.         for(int i=0;i<m.length;i++){
  20.             for(int j=0;j<m[0].length;j++){
  21.                 System.out.print(m[i][j]);
  22.             }
  23.             System.out.println();
  24.         }
  25.     }
  26.    
  27.     public static void rotacaoEsquerda(int[][] m){
  28.         int temp,i,j;
  29.         for(i=0;i<m.length;i++){
  30.             temp=m[i][0];
  31.             for(j=0;j<m[0].length-1;j++){
  32.                 m[i][j]=m[i][j+1];
  33.             }
  34.             m[i][j]=temp;
  35.         }
  36.     }
  37.     public static boolean verificarMatizContida(int[][] m,int[][] c){
  38.         for(int i=0; i<m.length-c.length+1;i++){
  39.             for(int j=0;i<m[0].length-c[0].length+1;j++){
  40.                
  41.                 boolean flag=true;
  42.                 for(int l=0;l<c.length;l++){
  43.                     for(int k=0;k<c[0].length;k++){
  44.                         if(m[i+l][j+k]!=c[l][k]){
  45.                             flag=false;
  46.                         }
  47.                     }
  48.                 }
  49.                 if(flag) return true;
  50.             }
  51.         }
  52.         return false;
  53.     }
  54.    
  55.    
  56.     public static void main(String[] args) {
  57.         System.out.print("Numero de Linhas:");
  58.         int l=in.nextInt();
  59.         while(l<=0){
  60.             System.out.print("ERRO: Numero de Linhas Invalido");
  61.             System.out.print("Numero de Linhas:");
  62.             l=in.nextInt();
  63.         }
  64.         System.out.print("Numero de Culunas:");
  65.         int c=in.nextInt();
  66.         while(c<=0){
  67.             System.out.print("ERRO: Numero de Culunas Invalido");
  68.             System.out.print("Numero de Culunas:");
  69.             c=in.nextInt();
  70.         }
  71.         int[][] mat1=criarMatriz(l,c);
  72.      
  73.         int[][] mattemp=mat1;
  74.         rotacaoEsquerda(mattemp);
  75.         mostarMatiz(mattemp);
  76.      
  77.         int[][] mat2=criarMatriz(4,4);
  78.         if(verificarMatizContida(mat1,mat2)){
  79.             System.out.print("Matriz Contida");
  80.         }else{
  81.             System.out.print("Matriz Não Contida");
  82.         }
  83.        
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement