Posts

Showing posts from 2016

Pre-compiled Headers

A precompiled header is a (c and c++) header that is compiled into intermediate form that is faster to process for the computer. Turbo C++ can generate (and subsequently use) pre-compiled headers for your projects.   Pre-compiled headers are header files that are compiled once, then used over and over again in their compiled state.  Using Pre-compiled Headers To control the use of pre-compiled headers, do one of the following:   1) Turn on the [X] Pre-compiled Headers option in the Options -> Compiler->  Code Generation dialog box.   The IDE bases the name of the pre-compiled header file on the project name, creating <project>.SYM   2) Use the - H, -H=<filename>, and -Hu command-line options with TCC.EXE.   3) Use the hdrfile and hdrstop pragmas inside your code.    Code Generation dialog box t his dialog box is where you select the memory model you'll be using and any options you find necessary for the type of code you want to generate

Alternating character

Shashank likes strings in which consecutive characters are different. For example, he likes ABABA , while he doesn't like ABAA . Given a string containing characters and only, he wants to change it into a string he likes. To do this, he is allowed to delete the characters in the string. Your task is to find the minimum number of required deletions. Input Format The first line contains an integer , i.e. the number of test cases. The next lines contain a string each. Output Format For each test case, print the minimum number of deletions required. Constraints length of string Sample Input 5 AAAA BBBBB ABABABAB BABABA AAABBB Sample Output 3 4 0 0 4 Explanation AAAA A , 3 deletions BBBBB B , 4 deletions ABABABAB ABABABAB , 0 deletions BABABA BABABA , 0 deletions AAABBB AB , 4 deletions because to convert it to AB we need to delete 2 A's and

Cut the sticks problem solution

You are given sticks, where the length of each stick is a positive integer. A cut operation is performed on the sticks such that all of them are reduced by the length of the smallest stick. Suppose we have six sticks of the following lengths: 5 4 4 2 2 8 Then, in one cut operation we make a cut of length 2 from each of the six sticks. For the next cut operation four sticks are left (of non-zero length), whose lengths are the following: 3 2 2 6 The above step is repeated until no sticks are left. Given the length of sticks, print the number of sticks that are left before each subsequent cut operations . Note: For each cut operation , you have to recalcuate the length of smallest sticks (excluding zero-length sticks). Input Format The first line contains a single integer . The next line contains integers: a 0 , a 1 ,...a N-1 separated by space, where a i represents the length of i th stick. Output Format For each operation, print the number of sticks

EVEN TRAINING

Maria loves playing soccer. Because she wants to play professionally when she grows up, she tracks her training by marking her calendar with a on the days that she trained, and a on the days she did not. She also loves math, and wants your help connecting her soccer training with what she's learning about even and odd numbers in school. Given days of Maria's calendar history, print whether or not she trained for an even number of days (either or ), followed by the total number of days she trained. Note: Code demonstrating how to read input from stdin is provided in your editor. Input Format The first line contains an integer, , denoting the number of days Maria tracked in her calendar. The next line contains space-separated integers describing whether or not Maria trained each day. Recall that the number indicates that she did train, and indicates she did not. Constraints Output Format Your output should consist of space-separat

Diagonal Difference

Print the absolute difference between the two sums of the matrix's diagonals as a single integer. Sample Input 3 11 2 4 4 5 6 10 8 -12 Sample Output 15 Explanation The primary diagonal is: 11       5             -12 Sum across the primary diagonal: 11 + 5 - 12 = 4 The secondary diagonal is:             4       5 10 Sum across the secondary diagonal: 4 + 5 + 10 = 19 Difference: |4 - 19| = 15 #include<iomanip.h> int main(){     int n;     cin >> n;                  int   m[n][n],i,j,sum=0,sum2=0; for(i=0;i<n;i++) { for(j=0;j<n;j++) { cin>>m[i][j]; } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i==j) sum+=m[i][j]; if(i+j==n-1) sum2+=m[i][j]; } } cout<<abs(sum-sum2);     return 0; }