Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

CAO Stage-1 CodeChef Solution

Problem -CAO Stage-1 CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.

CAO Stage-1 CodeChef Solution in C++14

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t ;
	 cin>>t ;
	  while(t--){
	      int n,m ;
	      cin>>n>>m ;
	      char arr[n][m] ;
	      for(int i=0;i<n;i++){
	          for(int j=0;j<m;j++){
	              cin>>arr[i][j] ;
	          }
	      }
	     
	      if(n<=4 || m<=4)
	      cout<<"0"<<endl ;
	      else{
	           int count=0 ;
	          for(int i=2;i<n-2;i++){
	              for(int j=2;j<m-2;j++){
	                 int yas=2 ;
	                    int count5=0;
	                 if(arr[i][j]=='#')
	                  count5++ ;
	                  int test1 =i,test2=j ;
	                   int test3 =i,test4=j ;
	                   int test5 =i,test6=j ;
	                   int test7 =i,test8=j ;
	            int count1=0,count2=0,count3=0,count4=0 ;
	          
	                 while(yas--){
	                     if(arr[--test1][test2]=='#')
	                     count1++ ;
	                     if(arr[++test3][test4]=='#')
	                     count2++;
	                     if(arr[test5][--test6]=='#')
	                      count3++ ;
	                      if(arr[test7][++test8]=='#')
	                      count4++;
	                     
	                 }
	                 int pra = count1+count2+count3+count4 ;
	                 
	                 if(pra==0 &&count5==0)
	                 count++ ;
	                  
	              }
	          }
	           cout<<count<<endl ;
	      }
	     
	        
	  }
	
	return 0;
}

CAO Stage-1 CodeChef Solution in PYTH 3

# cook your dish here
for _ in range(int(input())):
    r, c = [int(i) for i in input().split()]
    m = []
    for _ in range(r):
        m.append(input())
    ans = 0
    for i in range(2, r-2):
        for j in range(2, c-2):
            if m[i][j] == '^' and m[i-2][j] == '^' and m[i-1][j] == '^' and m[i+1][j] == '^' and m[i+2][j] == '^' and m[i][j-2] == '^' and m[i][j-1] == '^' and m[i][j+1] == '^' and m[i][j+2] == '^':
                ans+=1
    print(ans)

CAO Stage-1 CodeChef Solution in C

#include <stdio.h>

int main()
{
	int t;
	
	scanf("%d",&t);
	
	while(t--)
	
	{
	    int r,c;
	    
	    scanf("%d %d\n",&r,&c);
	    
	    char arr[51][51];
	    
	    for(int m=0;m<r;m++)
	    
		{
		    
		     	scanf("%s",&arr[m]);
		     	
		}
	   
	   
	    int count=0;
	    
	    for(int i=2;i<r-2;i++)
	    {
	        for(int j=2;j<c-2;j++)
	        {
	            if(arr[i][j]=='^'&&arr[i-2][j]=='^'&&arr[i-1][j]=='^'&&arr[i+1][j]=='^'&&arr[i+2][j]=='^'&&arr[i][j-2]=='^'&&arr[i][j-1]=='^'&&arr[i][j+1]=='^'&&arr[i][j+2]=='^')
	            count++;
	            
	        }
	    }
	    printf("%d\n",count);
	}
	return 0;
}

CAO Stage-1 CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out));
		int tt=Integer.parseInt(reader.readLine().trim());
		while(tt-->0){
		    int[] input=parseInt(reader.readLine().trim());
		    int r=input[0], c=input[1];
		    char[][] grid=new char[r][c];
		    for(int i=0;i<r;i++){
		        grid[i]=reader.readLine().trim().toCharArray();
		    }
		    int[][] lr=new int[r][c], rl=new int[r][c], ud=new int[r][c], du=new int[r][c];
		    for(int i=0;i<r;i++){
		        for(int j=0, k=c-1;j<c;j++, k--){
		            if(grid[i][j]=='^'){
		                if(j==0){
		                    lr[i][j]=1;
		                }else{
		                    lr[i][j]+=1+lr[i][j-1];
		                }
		            }
		            if(grid[i][k]=='^'){
		                if(k==c-1){
		                    rl[i][k]=1;
		                }else{
		                    rl[i][k]=1+rl[i][k+1];
		                }
		            }
		        }
		    }
		    
		    for(int i=0;i<c;i++){
		        for(int j=0, k=r-1;j<r;j++, k--){
		            if(grid[j][i]=='^'){
		                if(j==0){
		                    ud[j][i]=1;
		                }else{
		                    ud[j][i]=1+ud[j-1][i];
		                }
		            }
		            if(grid[k][i]=='^'){
		                if(k==r-1){
		                    du[k][i]=1;
		                }else{
		                    du[k][i]=1+du[k+1][i];
		                }
		            }
		        }
		    }
		    int count=0;
		    
		    for(int i=0;i<r;i++){
		        for(int j=0;j<c;j++){
		            if(i>0 && j>0 && i<r-1 && j<c-1){
		                if(grid[i][j]=='#'){
		                    continue;
		                }
		                int k=min(lr[i][j-1], rl[i][j+1], ud[i-1][j], du[i+1][j]);
		                if(k>=2){
		                    count++;
		                }
		            }
		        }
		    }
		    writer.write(count+"\n");
		}
		writer.flush();
	}
	
	private static int min(int ...a){
	    int ans=a[0];
	    for(int i: a){
	        ans=Math.min(ans, i);
	    }
	    return ans;
	}
	
    
    private static int[] parseInt(String str) {
        String[] parts=str.split("\\s+");
        int[] ans=new int[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Integer.parseInt(parts[i]);
        }
        return ans;
    }

    private static long[] parseLong(String str) {
        String[] parts=str.split("\\s+");
        long[] ans=new long[parts.length];
        for(int i=0;i<ans.length;i++){
            ans[i]=Long.parseLong(parts[i]);
        }
        return ans;
    }
}

CAO Stage-1 CodeChef Solution in PYTH

t = int(raw_input())
for i in range(t):
	st = raw_input().split()
	R = int(st[0])
	C = int(st[1])
	A = [[0 for x in range(C)] for y in range(R)]
	for y in range(R):
		st = raw_input().strip()
		for x in range(C):
			if st[x] == '^':
				A[y][x] = 1
			# endif
		# endfor x
	# endfor y
	r = 0
	if (R > 4) and (C > 4):
		for y in range(2,R-2):
			for x in range(2,C-2):
				n = A[y][x]+A[y][x+1]+A[y][x+2]+A[y][x-1]+A[y][x-2]+A[y+1][x]+A[y+2][x]+A[y-1][x]+A[y-2][x]
				if n == 9:
					r += 1
				# endif
			# endfor x
		# endfor y
	# endif
	print r
# endfor i

CAO Stage-1 CodeChef Solution in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ACO
{
class Program
{
public static int tester = 0;
public static int hamed(char[,] arr)
{
if (arr[0, 2] == '^' && arr[1, 2] == '^' && arr[2, 2] == '^' && arr[3, 2] == '^' && arr[4, 2] == '^' && arr[2, 0] == '^' && arr[2, 1] == '^' && arr[2, 3] == '^' && arr[2, 4] == '^')
return 1;
return 0;
}
public static void all()
{
tester = 0;
string[] tokens = Console.ReadLine().Split();
int r = int.Parse(tokens[0]);
int c = int.Parse(tokens[1]);
int R = r - 4;
int C = c - 4;
char[,] marr = new char[r, c];
for (int i = 0; i < r; i++)
{
string g = Console.ReadLine();
for (int j = 0; j < c; j++)
{
marr[i, j] =(char)(g[j]);
}
}
char[,] test = new char[5, 5];
for (int i = 0; i < R; i++)
{
for (int k = 0; k < C; k++)
{
for (int j = 0; j < 5; j++)
{
for (int l = 0; l < 5; l++)
{
test[j, l] = marr[j + i, l + k];
}
}
int test1 = hamed(test);
if (test1 == 1)
{
tester++;
}
}
}
}
static void Main(string[] args)
{
int d = int.Parse(Console.ReadLine());
int[] s = new int[d];
for (int i = 0; i < d; i++)
{
all();
s[i] = tester;
}
for (int i = 0; i < d; i++)
{
Console.WriteLine(s[i]);
}
Console.ReadLine();
}
}
}
CAO Stage-1 CodeChef Solution Review:

In our experience, we suggest you solve this CAO Stage-1 CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the CAO Stage-1 CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this CAO Stage-1 CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

Your email address will not be published. Required fields are marked *