Question : Find the number of "\n"(new line character) present in any string.
Input : String s = "Shroud is\n a godlike player in\n video gaming community."
Output : 2
Here is my code :
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int nseq=0;
string s;
cin>>s;
for(int i=0;i<s.length()-1;i++)
{
if(s.substr(i,i+1)=="\n")
{
nseq++;
}
}
cout<<nseq<<endl;
}