Can anybody help me with this beginner Competitive programming problem in C? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Can anybody help me with this beginner Competitive programming problem in C?

Question link: https://codeforces.com/problemset/problem/344/A Question name: Magnets (A) How do I solve this problem?

21st May 2021, 9:34 AM
Sandesh Adhikari
Sandesh Adhikari - avatar
4 Answers
+ 1
Start 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
21st May 2021, 10:01 AM
YUGRAJ
+ 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.
21st May 2021, 10:12 AM
sarada lakshmi
sarada lakshmi - avatar
+ 1
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 } }
21st May 2021, 10:32 AM
Mihail
Mihail - avatar
+ 1
Hey Sandesh Adhikari I'm totally agree with Martin Taylor , I recomment to learn C++ !
21st May 2021, 1:00 PM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar