while using two getline functions ... one of them doesn't execute... i know its crazy but !! can anyone help ? Thanx

#include<bits/stdc++.h>
using namespace std;
void ck(string s)
{
string s1=“abcdefghijklmnopqrstuvwxyz”;
int len;
string s2=s;
int pos=0;
long int sum=0;
sort(s2.begin(),s2.end());
len=s1.length();
int i;
for(i=0;i<len;i++)
{
pos=s2.find(s1[i]);
if(pos<0)
{
sum=sum+s1[i]-96;

        }
       s2.erase(std::remove(s2.begin(), s2.end(), s1[i]), s2.end());
    }
cout<<sum<<endl;

}

int main()
{
    int n=10;
    cin>>n;

    string s,s2;

    while(n>0)
    {

        getline(cin,s2); //doesn't execute the first time :/

        getline(cin,s);
        ck(s);


        n--;
    }
    return 0;
}

Hey @ark_srivastav,

It’s working, I have checked. provide the test case for which it is not working.

Thats because the first getline takes the stray newline character left after inputting n. If you put string and n in same line , I think both will then work.

What happens is that getline takes input till it encounters a new line char. After taking n as input, the cursor is at the newline char next to it, and so it gets taken by first getline. Then the second one works as intended