- 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?
5 Respuestas
+ 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
+ 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.
+ 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
}
}
+ 1
Hey Sandesh Adhikari
I'm totally agree with Martin Taylor , I recomment to learn C++ !