Gift carpet

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.4 kB
18
Indexable
Never
import java.util.*;
public class si2 {
    public static void main(String[] args) {
        int t;
        Scanner sc = new Scanner(System.in);
        t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            char[][] carpetMat = new char[n][m];
            for (int j = 0; j < n; j++) {
                String line = sc.next();
                for (int k = 0; k < m; k++) {
                    carpetMat[j][k] = line.charAt(k);
                }
            }
            // for (int j = 0; j < n; j++) {
            //     for (int k = 0; k < m; k++) {
            //         System.out.print(carpetMat[j][k] + " ");
            //     }
            //     System.out.println();
            // }
            char words[] = {'v','i','k','a'};
            int p = 0,vikaCount = 0;
            for(int j = 0;j < m;j++){
                for(int k = 0;k < n;k++){
                    if(carpetMat[k][j] == words[p]){
                        vikaCount++;
                        p++;
                        break;
                    }
                    
                }
            }
 
            if(vikaCount == 4){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
            
        }
    }
}