I want this in C programming i wrote it in C++: #include using namespace std; int main() {    int tc,m,n,ts=1;    string str;    cout<<"No of test cases :";    cin>>tc; // reading number of testcases    while(ts<=tc)    {        vector v1; // vector to store string        cin>>n>>m;        for(int i=0;i>str;            v1.push_back(str); // push_back into the vector        }        int count=0; // count of starts        for(int i=0;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I want this in C programming i wrote it in C++:

#include <bits/stdc++.h>
using namespace std;
int main()
{
   int tc,m,n,ts=1;
   string str;
   cout<<"No of test cases :";
   cin>>tc; // reading number of testcases
   while(ts<=tc)
   {
       vector<string> v1; // vector to store string
       cin>>n>>m;
       for(int i=0;i<n;i++) // reading string from user
       {
           cin>>str;
           v1.push_back(str); // push_back into the vector
       }
       int count=0; // count of starts
       for(int i=0;i<n-1;i++) // iterate over each string
       {
           int t1=0,t2=0,j=0;
           while(j<m)
           {
               if(v1[i].at(j)=='-') // if - occur go until # found
               {
                   while(j!=m && v1[i].at(j)!='#')
                   {
                       if(v1[i+1].at(j)=='-') // if we have - at same position in next line don't count using t2
                       t2=1;
                       j=j+1;
                   }
                   if(t2==0) // if no such - at next level in same - occur at line
                   count=count+1; // increment count
                   t2=0;
               }
               else
               j=j+1;
           }
       }
       int t3=0;
       for(int j=0;j<m;j++)//iterate over last string
       {
           if(v1[n-1].at(j)=='-') // if - occur go until # found and count++
           {
               t3=1;
           }
           else if(t3==1)
           {
               count+=1;
               t3=0;
           }
       }
       cout<<"Case "<<ts<<":"<<count<<endl; // print result
       ts=ts+1;
   }
}

 

 you should write such an analysis program which counts the number of stars visible in an bitmap image. An image consists of pixels, and each pixel is either black or white (represented by the characters # and -, respectively). All black pixels are considered to be part of the sky, and each white pixel is considered to be part of a star. White pixels that are adjacent vertically or horizontally are part of the same star.

Input

Each test case begins with a line containing a pair of integers 1≤m, n≤100. This is followed by mm lines, each of which contains exactly nn pixels. Input contains at least one and at most 50 test cases, and input ends at the end of file.

Output

For each case, display the case number followed by the number of stars that are visible in the corresponding image. Follow the format of the sample output.

Expert Solution
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education