MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / main

Function main

CodeChef_problems/CHEFSTR1/Solution.cpp:6–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4using namespace std; //std for using standard library for every function avoiding repitition
5
6int main() //main function to perform calculation
7{
8 int n; //integer n(no. of test cases) defined
9 scanf("%d",&n); //taking input n(no. of test cases) using scanf()
10 for(int i=0;i<n;i++){ //for loop n times for all test cases
11 int m; //integer m defined
12 long long x=0; //long long type value x(strings to skip) initialized to 0
13 scanf("%d",&m); //taking input m(no. of strings to pluck) using scanf()
14 vector<int> v; //defining vector v of type int to store strings to be plucked
15 for(int j=0;j<m;j++){
16 int a; // integer a defined
17 scanf("%d",&a); //taking integer input a(place of string to be plucked)
18 v.push_back(a); //adding place of string to be plucked in vector
19 }
20 for(int k=1;k<m;k++){ //for loop in vector v of length m
21 x+=((abs(v[k]-v[k-1]))-1); //abs() function to take modulus if returning back(v[k]-v[k-1] < 0)
22 //and increasing x by no. of strings to skip between v[k] and v[k-1]
23 //and subtracting 1 because both v[k] and v[k-1] are plucked that don't add to skip no. x
24 }
25 printf("%ld\n",x); //output no. of strings to skip
26 }
27 return 0;
28}
29

Callers

nothing calls this directly

Calls 1

absFunction · 0.85

Tested by

no test coverage detected