#include <iostream> using namespace std; int main() { long int t; cin>>t; while(t--) { char s[1008]; cin>>s; long int n=0,steps=0; for(int i=0;s[i]!='\0';i++) { if(s[i]=='1')n++; } if(n==1); else steps++; while(n!=1) { long int m=0; while(n!=0) { int y=n&1; if(y==1) { m++; } n=n>>1; } n=m; steps++; } cout<<steps<<"\n"; } return 0; }
This code gave the right answers for the test cases but gave wrong answers when i submitted it! what corner test cases am i missing? or is there any mistake in the code?
Asked by: Aditya_Gupta on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.