How do i store this input as an array

We are given N characters in a line and i want to do this:
For eg. if n=3 and line is = . * .
then my array should be [0,1,0].
Here “.”=0 and " * " = 1. Please help me how to do this

string s;
cin>>s;
int a[s.length()];
for(i=0;i<s.length();i++)
{
if(s[i]==’.’)
a[i]=0;
else
a[i]=1;
}

You can also read the input string in a character array, not much change in remaining code

2 Likes

In python it is easy. You can do like this in python for storing input as an array.

n = int(input())#It is the general form of taking integer input

n = list(map(int,input().split()))#It is the way to store a list of integer input
3 Likes