5 Answers
New AnswerQuestion link: https://codeforces.com/problemset/problem/344/A Question name: Magnets (A) How do I solve this problem?
5/21/2021 9:34:46 AM
Sandesh Adhikari5 Answers
New AnswerStart you ans with value 1 now every time you get magnet check if the first bit of this magnet is equal to last bit of previous magnet if so then increacase ans by 1
Iterate over the list of values. At each iteration compare the ith value with (i+1)th value.. If, they are not equal, then increment count by 1. Finally, print the count value.
counter=0; for(int i=0;i<n-1;i++){//n= number of dominoes if(arr[i]%10!=arr[i+1]%10){ counter++;//number of groups } }
Hey Sandesh Adhikari I'm totally agree with Martin Taylor , I recomment to learn C++ !
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message