Code Exercise – BIQ-001
Mr.X owns a small business in a region with poor law-and-order. Recently his warehouse has been plagued by thieves. Gangs of thieves raid over his warehouse from time to time, stealing his raw material, affecting his business. He has studied the occurrances and noticed it that they are cyclical.

Assuming that a work week starts every Monday, and Sat and Sun are holidays, predict the total number of days when business would be affected.

Picture (Metafile) please see attached jpgeg

e.g. (Refer to Image) He has noticed that currently there seem to be 2 gangs. Gang1 raids every 4 days, whereas Gang2 strikes every 6 days.

Raids On Holidays are okay - since there is no raw material on those days. If more than gang raids the warehouse on a particular day, it is still counted as one bad day. So the answer in this case is 5.

Sample Input: (file)
The input is in the form of text file containing test cases.
2
2
4 6
21
3
3 4 8
14

The first line indicates the number of test cases - 2 above. Each test case is made up of 3 lines.
The first line of every test case indicates the number of gangs, n. (i.e 2 for TestCase#1)
The next line contains n integers, where each number k indicates that the gangi strikes every k days. (i.e. 4 and 6 for TestCase#1)

The next line is the number of days d, for which the prediction is needed. 0 <= d <= 365 (i.e. 21 days for TestCase#1)

Sample output: (can be printed to console.. via printf or equivalent)
5
5

Your program should accept the name of the input file (in the same dir) as a command line argument and print out the output of each test case on a new line.

Hi , this is good question , Please any one help me out...
Please give me solution till tomo morning 10 am

This looks like fun.
Since it can be done in your language of choice, would you prefer it in C or some other language?

Are you supposed to explain it when it's finished?

This looks like fun.
Since it can be done in your language of choice, would you prefer it in C or some other language?

Are you supposed to explain it when it's finished?

yes...
I want it in C language.
everything is explained, please also see attached files

yes...
I want it in C language.
everything is explained, please also see attached files

Please explain if u can,
I need it very urgently...
When can u give me ...
Plz its a req

This compiles on both Visual Studio and gcc on Solaris.
The comments in the code explain what you need to know.
You can adjust the code if you think each gang should not "hit" on the first day.

#pragma warning(disable : 4996) /* Microsoft _CRT_SECURE_NO_WARNINGS */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NUM_LINES_PER_CASE 3

/* Structre for holding the records once loaded from the file */
typedef struct tagTEST_CASES
{
	unsigned short numNumOfGangs;
	unsigned short* pNumHowOften;
	unsigned short numSpanDays;
} TEST_CASES;

int main(int argc, char** argv)
{
	auto	FILE* pFile = NULL;
	auto	TEST_CASES* pArrTestCases = NULL;
	auto	char* pStrToken		= 0;
	/**/
	auto	char strData[128]		= {'\0'};
	/**/
	auto	int intNumTestCases	= 0;
	auto	int intGangLoop		= 0;
	auto	int intCaseLoop		= 0;
	auto	int intSpanLoop		= 0;
	
	/* If user has not specified a file, show usage message */
	if(argc < 2)
	{
		puts("TestCases fileName\n\twhere filename is the test case input file");
		return 1;
	}
	
	/* If the input file is not found or not readable, quit with message */
	if(NULL == (pFile = fopen(argv[1], "r+b")))
	{
		puts("Cannot open input file.");
		return 2;
	}
	
	/* Read the first line to get the number of test cases */
	if(NULL != fgets(strData, sizeof(strData), pFile))
	{
		intNumTestCases = atoi(strData);
	}
	
	/* Adjust the size of the test case elements based on the number of cases */
	pArrTestCases = (TEST_CASES*)  malloc(sizeof(TEST_CASES)*intNumTestCases);
	
	/* Loop through each of the test cases */
	for(intCaseLoop=0; intCaseLoop < intNumTestCases; intCaseLoop++)
	{
		if(feof(pFile))
		{
			break;
		}
		
		/* get the number of gangs and store it in the structure */
		fgets(strData, sizeof(strData), pFile);	
		pArrTestCases[intCaseLoop].numNumOfGangs = (unsigned short) atoi(strData);
		
		/* get the "hit" rate and adjust the "how often" array */
		fgets(strData, sizeof(strData), pFile);
		pArrTestCases[intCaseLoop].pNumHowOften =
			(unsigned short*) malloc(
				sizeof(unsigned short)*pArrTestCases[intCaseLoop].numNumOfGangs);
		
		/* convert the "how often" array into the structure */
		intGangLoop = 0;
		pStrToken = strtok(strData, " ");
		while(NULL != pStrToken)
		{
			pArrTestCases[intCaseLoop].pNumHowOften[intGangLoop++] =
			 (unsigned short) atoi(pStrToken);
			pStrToken = strtok(NULL, " ");
		}
		
		/* Get the span of days */
		fgets(strData, sizeof(strData), pFile);
		pArrTestCases[intCaseLoop].numSpanDays = (unsigned short) atoi(strData);
	}

	fclose(pFile);
	
	/* Display the days the store will be "hit" */
	for(intCaseLoop=0; intCaseLoop < intNumTestCases; intCaseLoop++)
	{	/* for each test case */
		for(intSpanLoop=0; intSpanLoop < pArrTestCases[intCaseLoop].numSpanDays; intSpanLoop++)
		{	/* for each day in the span */
			for(intGangLoop=0; intGangLoop < pArrTestCases[intCaseLoop].numNumOfGangs; intGangLoop++)
			{	/* for each gang */
				if(0 == (intSpanLoop % pArrTestCases[intCaseLoop].pNumHowOften[intGangLoop]))
				{	/* Tell when hit */
					printf("%d ", intSpanLoop+1);
				}
			}
		}
		
		printf("\n");	// separate test cases
	}
	
	/* clean up allocated memory */
	for(intCaseLoop=0; intCaseLoop < intNumTestCases; intCaseLoop++)
	{
		free(pArrTestCases[intCaseLoop].pNumHowOften);
	}
	
	free(pArrTestCases);
	
	return 0;
}

i dont know where to post my question iam sorry..........can anybody give me the c code for EDID function testcases like....
if we change different kind of resolution monitors for cpu the video have to accept it ... how to write a c code to test it

please give some references about test cases by explaining in a vedio...!

Erm, you do realise that this is a SEVEN year old quesation that was last posted to SIX years ago, right?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.