How to write inside a panel box using a label? - c#

Here is the code for writing the letter G with * representation inside text box. Now I want to write this inside a panel using a label. How can I do it?
I have drawn label box inside panel and want to write inside label.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication31
{
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void A(object sender, EventArgs e) {
int row, column;
for (row = 0; row <= 6; row++) {
for (column = 0; column <= 6; column++) {
if ((column == 1 && row != 0 && row != 6) ||
((row == 0 || row == 6) && column > 1 && column < 5) ||
(row == 3 && column > 2 && column < 6) ||
(column == 5 && row != 0 && row != 2 && row != 6))
textBox1.AppendText("*");
else
textBox1.AppendText(" ");
}
textBox1.AppendText(Environment.NewLine);
}
textBox1.AppendText(Environment.NewLine);
}
}
}

For a TextBox:
textBox1.AppendText(text);
For a Label:
label1.Text += text;
Build your text separately using a StringBuilder.
StringBuilder builder = new StringBuilder();
int row, column;
for (row = 0; row <= 6; row++)
{
for (column = 0; column <= 6; column++)
{
if ((column == 1 && row != 0 && row != 6) ||
((row == 0 || row == 6) && column > 1 && column < 5) ||
(row == 3 && column > 2 && column < 6) ||
(column == 5 && row != 0 && row != 2 && row != 6))
builder.Append("*");
else
builder.Append(" ");
}
builder.Append(Environment.NewLine);
}
builder.Append(Environment.NewLine);
string text = builder.ToString();

Assuming you are able to do your need using a textbox,
However, label controls are not meant to be multi-line by default. Textboxes can be made like that using the multiline attribute (Hence you need to check compatibility)
Refactor your code as
private string CreateGraphicString() {
StringBuilder builder = new StringBuilder();
int row, column;
for (row = 0; row <= 6; row++) {
for (column = 0; column <= 6; column++) {
if ((column == 1 && row != 0 && row != 6) ||
((row == 0 || row == 6) && column > 1 && column < 5) ||
(row == 3 && column > 2 && column < 6) ||
(column == 5 && row != 0 && row != 2 && row != 6))
builder.Append("*");
else
builder.Append(" ");
}
builder.AppendLine();
}
builder.AppendLine();
}
return builder.ToString();
}
myLabel.Text = builder.AppendLine();
myTextbox.Text = builder.AppendLine();

Related

How to use enter as a tab in datagridview

I want to use enter key as a alternate of Tab key in datagridview
I have four column when I type in third column it should move to the fourth column of same row by pressing of enter, it moves to next row instead of next column.
I am using the following code
if (e.KeyData == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
if (col < dataGridView1.ColumnCount - 1)
{
col++;
}
else
{
col = 0;
row++;
}
if(row == dataGridView1.RowCount)
dataGridView1.Rows.Add();
dataGridView1.CurrentCell = dataGridView1[col, row];
e.Handled = true;
}
This code is working properly.
should be false allowuser to add row.
if (e.KeyCode == Keys.Enter)
{
int col = dataGridView1.CurrentCell.ColumnIndex;
int row = dataGridView1.CurrentCell.RowIndex;
if (row == dataGridView1.Rows.Count - 1 && col < dataGridView1.Columns.Count - 1)
{
dataGridView1.CurrentCell = dataGridView1.Rows[row].Cells[col + 1];
dataGridView1.Focus();
}
else if (col == dataGridView1.Columns.Count - 1 && row == dataGridView1.Rows.Count - 1)
{
dataGridView1.Rows.Add(1);
dataGridView1.CurrentCell = dataGridView1.Rows[row].Cells[0];
dataGridView1.Focus();
}

Animate pattern to move vom left to right and back in Console

I'm currently getting into c# and try to play around in the console.
I basically want to animate a logo in the console. I already wrote 2 methods to display the letters H and S with "#". Right now they're just written side by side. Now I want them to move from the left to the right and back. In the next step I'd also like to make the letters bigger and smaller every few frames. They have the size 5x7 now, so it would change every frame like this:
3x5 -> 5x7 -> 7x9.
My idea would be to to write the letters, move one column to the right, delete the old lines and print a new one.
Any tips on what I could do from here?
public class Program
{
static int row, col;
public static void Main(string[] args)
{
Console.CursorVisible = false;
WriteH();
WriteS();
}
public static void WriteH()
{
for (row = 0; row < 7; row++)
{
for (col = 0; col < 7; col++)
{
if ((col == 1 || col == 5) || (row == 3 && col > 1 && col < 6))
{
Console.Write("#");
}
else
{
Console.Write(" ");
}
}
Console.WriteLine();
}
}
public static void WriteS()
{
for (row = 0; row < 7; row++)
{
for (col = 0; col < 7; col++)
{
if (((row == 0 || row == 3 || row == 6) && col > 1 && col < 5)
|| (col == 1 && (row == 1 || row == 2 || row == 6))
|| (col == 5 && (row == 0 || row == 4 || row == 5)))
{
Console.SetCursorPosition(col+7, row);
Console.Write("#");
}
else
{
Console.SetCursorPosition(col+7, row);
Console.Write(" ");
}
}
Console.WriteLine();
}
}
}
If someone encounters the same problem,I now figured out how to do it using an endless while loop. Scaling the letters should be possible in the same way. The commented part was my first while loop, but just moves from left to right.
public class Program
{
static void Main(string[] args)
{
//WriteH();
//WriteS();
MoveLetters();
}
/*public static void MoveLetters()
{
int i = 0;
while (i < 100)
{
WriteH(i);
WriteS(i);
i++;
System.Threading.Thread.Sleep(20);
Console.Clear();
}
}*/
public static void MoveLetters()
{
int i = 0;
while (true)
{
for(i=0; i<100; i++)
{
WriteH(i);
WriteS(i);
System.Threading.Thread.Sleep(20);
Console.Clear();
}
for(i=100; i>0; i--)
{
WriteH(i);
WriteS(i);
System.Threading.Thread.Sleep(20);
Console.Clear();
}
}
}
public static void WriteH(int xPosition)
{
for (var row = 0; row < 7; row++)
{
for (var col = 0; col < 7; col++)
{
if ((col == 1 || col == 5) || (row == 3 && col > 1 && col < 6))
{
Console.SetCursorPosition(col + xPosition, row);
Console.Write("#");
}
}
Console.WriteLine();
}
}
public static void WriteS(int xPosition)
{
for (var row = 0; row < 7; row++)
{
for (var col = 0; col < 7; col++)
{
if (((row == 0 || row == 3 || row == 6) && col > 1 && col < 5)
|| (col == 1 && (row == 1 || row == 2 || row == 6))
|| (col == 5 && (row == 0 || row == 4 || row == 5)))
{
Console.SetCursorPosition(col + 7 + xPosition, row);
Console.Write("#");
}
}
Console.WriteLine();
}
}
}

Non square spiral matrix not printing correctly

I am having issues with this assignment I have. I am to print a spiral matrix which cannot be square, in other words the user should input the number of rows and columns.
Console.Write("Enter n: ");
int n = int.Parse(Console.ReadLine());
Console.Write("Enter m: ");
int m = int.Parse(Console.ReadLine());
int[,] matrix = new int[n,m];
int row = 0;
int col = 0;
string direction = "right";
int maxRotations = n * m;
for (int i = 1; i <= maxRotations; i++)
{
if (direction == "right" && (col > n - 1 || matrix[row, col] != 0))
{
direction = "down";
col--;
row++;
}
if (direction == "down" && (row > n - 1 || matrix[row, col] != 0))
{
direction = "left";
row--;
col--;
}
if (direction == "left" && (col < 0 || matrix[row, col] != 0))
{
direction = "up";
col++;
row--;
}
if (direction == "up" && row < 0 || matrix[row, col] != 0)
{
direction = "right";
row++;
col++;
}
matrix[row, col] = i;
if (direction == "right")
{
col++;
}
if (direction == "down")
{
row++;
}
if (direction == "left")
{
col--;
}
if (direction == "up")
{
row--;
}
}
// displej matrica
for (int r = 0; r < n; r++)
{
for (int c = 0; c < m ; c++)
{
Console.Write("{0,4}", matrix[r,c]);
}
Console.WriteLine();
}
Console.ReadLine();
}
My issue currently is that is not printing and at the same is printing in a spiral. In other words the spiral is kind of messed up.
If i run the code and enter 4 as the number of rows and 6 as the number of columns I get the following:
1 2 3 4 0 24
12 13 14 5 0 23
11 16 17 18 19 22
10 9 8 7 20 21
What am i doing wrong?
Your first two conditions check the same boundary (n):
if (direction == "right" && (col > n - 1 || matrix[row, col] != 0))
if (direction == "down" && (row > n - 1 || matrix[row, col] != 0))
I guess for "right" your boundary should be m.
if (direction == "right" && (col > m - 1 || matrix[row, col] != 0))
That's why it is "turning" early: n is 4. And that's exactly where it is turning. The rest are all follow-up errors.

How to check the surrounding cells of a specific cell in terms of a specific values in a rectangular array in C#

I used the following method to check the cells around a specific cell in terms of a given indexes (row & column) if it zeros or not, see this array:
The cell that I need to check the surroundings of zeros (horizontally, Vertically or diagonally) could be at the first row, last row, first column, last column or in between i.e. it could be any cell in the rectangular array depending to the "rowIndex" and "colIndex" which are passed to the method.
static Boolean TestZero(int[,] array,int colIndex, int rowIndex)
{
/*Check Corners*/
//First Corner
if ((rowIndex == 0) && (colIndex == 0))
{
if (array[1, 0] == 1 || array[0, 1] == 1 || array[1, 1] == 1) return false;
}
//Second Corner
if ((rowIndex == 0) && colIndex >= array.GetUpperBound(0))
{
if (array[array.GetUpperBound(0) - 1, 0] == 1 || array[array.GetUpperBound(0),1] == 1 || array[array.GetUpperBound(0)-1,1 ] == 1) return false;
}
//Third Corner
if ((rowIndex >= array.GetUpperBound(1)) && (colIndex == 0))
{
if (array[0, array.GetUpperBound(1) - 1] == 1 || array[1, array.GetUpperBound(1)] == 1 || array[1, array.GetUpperBound(1)-1] == 1) return false;
}
//Fourth Corner
if ((rowIndex >= array.GetUpperBound(1)) && (colIndex >= array.GetUpperBound(0)))
{
if (array[array.GetUpperBound(0), array.GetUpperBound(1) - 1] == 1 || array[array.GetUpperBound(0) - 1, array.GetUpperBound(1) - 1] == 1 || array[array.GetUpperBound(0) -1, array.GetUpperBound(1)] == 1) return false;
}
/* Check Boundries But Not Corners */
//First Row
if ((rowIndex == 0) && (colIndex != array.GetUpperBound(0)) && (colIndex != 0))
{
for (int i = rowIndex; i <= rowIndex + 1; i++)
{
for (int j = colIndex - 1; j <= colIndex + 1; j++)
{
if ((i != rowIndex) && (j != colIndex))
{
if (array[j,i] == 1) return false;
}
}
}
}
//Last Row
if ((rowIndex >= array.GetUpperBound(1)) && (colIndex != array.GetUpperBound(0)) && (colIndex != 0))
{
for (int i = rowIndex; i <= rowIndex - 1; i--)
{
for (int j = colIndex - 1; j <= colIndex + 1; j++)
{
if ((i != rowIndex) && (j != colIndex))
{
if (array[j,i] == 1) return false;
}
}
}
}
//First & Last Columns
if ((rowIndex != array.GetUpperBound(1)) && ((rowIndex != 0)))
{
//First column
if(colIndex==0)
{
for (int i = rowIndex-1; i <= rowIndex + 1; i++)
{
for (int j = colIndex; j <= colIndex + 1; j++)
{
if ((i != rowIndex) && (j != colIndex))
{
if (array[j,i] == 1) return false;
}
}
}
}
//Last Column
if (colIndex == array.GetUpperBound(0))
{
for (int i = rowIndex -1; i <= rowIndex + 1; i++)
{
for (int j = colIndex; j <= colIndex - 1; j--)
{
if ((i != rowIndex) && (j != colIndex))
{
if (array[j,i] == 1) return false;
}
}
}
}
}
/* In Between i.e. Not the Array Boundries */
if(colIndex!=0 && colIndex != array.GetUpperBound(0) && rowIndex !=0 && rowIndex != array.GetUpperBound(1)) {
for (int i = rowIndex - 1; i <= rowIndex + 1; i++)
{
for (int j = colIndex - 1; j <= colIndex + 1; j++)
{
if ((i != rowIndex) && (j != colIndex))
{
if (array[j,i] == 1) return false;
}
}
}
} // end if statment
return true;
}
I got some wrong result and I tried to figure out the problem, but I could not!.
Results:
1- Rectangular arrays (chromosomes in a genetic algorithm population):
2- The indexes of the cells that we need to check its surroundings:
|(2,3)||(2,3)||(0,1)||(1,3)||(0,3)||(1,3)|
3- Arrays that contains zero in at least one of the surrounding cells of each of the intended cells:
Chromosome 0 : True Chromosome 1 : True Chromosome 2 : False
Chromosome 3 : True Chromosome 4 : False Chromosome 5 : True
Any help to figure out why I got some wrong results!!.
From what I can see, your method checks if a cell is surrounded by cells filled with 1s and returns false if it is. Your code is too complicated for it because you try to look at everything as a different case instead of generilizing it making it very difficult to debug. The following method is an example of a better way to implement the check:
bool TestZero(int[,] mat, int row, int col)
{
int ones = 0, cells = 0;//define counters
//define bounderies
int rowLen = Math.Min(row + 1, mat.GetLength(0) - 1),
colLen = Math.Min(col + 1, mat.GetLength(1) - 1),
rowIdx = Math.Max(0, row - 1),
colIdx = Math.Max(0, col - 1);
for (int i = rowIdx; i <= rowLen; i++)
{
for (int j = colIdx; j <= colLen; j++)
{
//if it is our given index, continue
if (i == row && j == col)
continue;
++cells;//increment cells counter
if (mat[i, j] == 1)//if the value of the cell is 1
++ones;//increment the ones counter
}
}
return ones < cells;//if there are less cells with '1' then
//surrounding cells, return true.
}
What we do here is:
create two counters: one counts the amount of cells surrounding the given cell and another counts how many ones surround it.
We save the bounderies of the loops in variables:
rowLen: the last row index to visit. It is the smaller value between the row index of the given cell + 1 and the last row index in the matrix.
rowIdx: the starting row index to check in the loop. The bigger value between the row index of the given cell - 1 and the first row index in the matrix (0).
colLen: same as rowLen just for the columns.
colIdx: same as rowIdx just for columns.
Then we iterate over the mini-matrix we created with our bounderies. For each cell, if it not our given cell we increment the cells counter and if it is equal to 1, we increment the ones counter.
At the end, if the ones counter is smaller than the cells counter, we return true since our cell is not surrounded by 1s.
EDIT
The example above returns true if not all of the surrounding cells contain 1.
But it is possible to change the return value to match different cases:
If you want to return true only when there are 0 cells with 1, change the return line to the following: return ones == 0;
In this case, the cells counter is unecessary, only the ones counter is needed.
If you want to return true only when all the surrounding cells contain 1, change to the following: return ones == cells;
You can basically change the return value to whatever situation you need, it's very flexible.
As always, the first rule when programming is: break down the problem into smaller bits.
I'll be using C#7 features just for the fun of it. If you are not using C#7, consider translating it to previous versions as an excercise.
Ok, first step. You need neigbouring cells? Allright, lets get all possible neighbouring cells, not caring about wether they exist or not. We'll take care of that later; remember, one small problem at a time.
private static IEnumerable<(int Row, int Column)> GetAllNeighbouringCoordinates(int row, int column)
{
yield return (row - 1, column - 1);
yield return (row - 1, column);
yield return (row - 1, column + 1);
yield return (row, column + 1);
yield return (row + 1, column + 1);
yield return (row + 1, column);
yield return (row + 1, column - 1);
yield return (row, column - 1);
}
Ok, now we have a method that will give us all possible 8 neighbours. The order in which I'm returning them is clockwise, starting at the top left neighbour. Order is unimportant in this case, so consider it an implementation detail.
Now, we need someway to check if any given cell is valid. Ok, that seems easy too:
private static bool IsValidCoordinate((int Row, int Column) coord, int rowCount, int columnCount)
{
Debug.Assert(rowCount >= 0);
Debug.Assert(columnCount >= 0);
if (0 > coord.Row || coord.Row >= rowCount ||
0 > coord.Column || coord.Column >= columnCount)
return false;
return true;
}
Ok, that was pretty simply too. See how hard it is to introduce a bug in simple methods?
Also, notice the assertions at the start of the method. This method is not supposed to work with nonsensical values of rowCount and columnCount so I enforce that in code. Because the method is a private helper method, I can simply assert and not throw an exception. If an assertion fails in testing, I know I have a bug in my code.
Now, we just have to glue both things together. Lets build a method that returns the value of all neighbouring cells. We'll use some LINQ to remove the unsightly loops:
public static IEnumerable<T> GetNeighbouringCells<T>((int Row, int Column) coord, T[,] cells)
{
if (cells == null)
throw new ArgumentOutOfRangeException();
if (!IsValidCoordinate(coord, cells.GetLength(0), cells.GetLength(1)))
throw new ArgumentOutOfRangeException();
return GetAllNeighbouringCoordinates(coord.Row, coord.Column)
.Where(c => IsValidCoordinate(c, cells.GetLength(0), cells.GetLength(1)))
.Select(c => cells[c.Row, c.Column]);
}
And there you go, now you have a simple method that will return every neighbouring value of any given cell.
Now, you need all cells where at least one neighbouring cell is zero? Easy peasy:
public static IEnumerable<(int Row, int Column)> CellsWithAtLeastOneNeighbourEqualTo<T>(
this T[,] cells, T value)
{
for (var row = 0; row < cells.GetLength(0); row++)
{
for (var column = 0; column < cells.GetLength(1); column++)
{
if (GetNeighbouringCells((row, column), cells).Any(c => c.Equals(value)))
{
yield return (row, column);
}
}
}
}
And now if you take it for a small ride:
var cells = new[,] { { 0, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } };
var n = cells.CellsWithAtLeastOneNeighbourEqualTo(0).ToList();
You will get the expected results:
[0, 1]
[1, 0]
[1, 1]
This seems like a simple game of life program. You should not check everything invidually but use for example a function to check if given a cell's x and y coordinates exist in the table.
Pseudocode:
for each cell in celltable
for each cell surrounding
if cell index is valid && alive
alive = alive + 1;
endif
endfor
if alive is valid
add cell to retList
alive = 0;
endfor
No-one wants to debug huge if-else systems.
This is not good in performance, but may solve your problem.
PS. please notice that I renamed your colIndex and rowIndex to x and y.
static bool TestZero(int[,] array, int x, int y)
{
try
{
if (array[x - 1, y - 1] == 1) return false;
}
catch { }
try
{
if (array[x, y - 1] == 1) return false;
}
catch { }
try
{
if (array[x + 1, y - 1] == 1) return false;
}
catch { }
try
{
if (array[x - 1, y] == 1) return false;
}
catch { }
try
{
if (array[x, y] == 1) return false;
}
catch { }
try
{
if (array[x + 1, y] == 1) return false;
}
catch { }
try
{
if (array[x - 1, y + 1] == 1) return false;
}
catch { }
try
{
if (array[x, y + 1] == 1) return false;
}
catch { }
try
{
if (array[x + 1, y + 1] == 1) return false;
}
catch { }
return true;
}
I test with your original case (the first image in your post), use the following code.
private static int[,] array = { { 0, 0, 1, 1 }, { 0, 0, 0, 1 }, { 0, 1, 1, 1 }, { 1, 0, 1, 0 } };
static void Main(string[] args)
{
for (int i = 0; i <= array.GetUpperBound(0); i++)
{
for (int j = 0; j <= array.GetUpperBound(1); j++)
{
Console.Write(TestZero(array, i, j) + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
And the result is
True False False False
False False False False
False False False False
False False False False
I'm going to test more cases, but at last your can take a try now.

How to assign two lists in a linq query with some conditions?

I've two lists and I assign one of them this way:
var query = Enumerable.Range(0, 1440).Select((n, index) =>
{
if ((index >= 525 && index <= 544) || (index >= 600 && index <= 749) || (index >= 810 && index <= 1079) || (index >= 1300 && index <= 1439))
return 0;
else if (index >= 1080 && index <= 1299)
return 1;
else if (index >= 545 && index <= 599)
return 3;
else if (index >= 750 && index <= 809)
return 4;
else
return 2;
}).ToList();
My second list is named lst2. I want to assign it "0" or "1" depending on my first list query. So, if query is "1" or "2", lst2's same indices and previous indices that are "0" value, should be "1". If the query list is "3" or "4", lst2's same indices and previous indices that are "1" value, should be "0". In addition, if the query's first indice(s) has "3" or "4" value, then lst2's same indice(s) should be "0". For example;
query = {3,3,3,0,0,0,2,2,0,0,0,0,4,4,4,4,0,0,0,0,1,1,1,0,0,2,2,0,0,4,4}
lst2 = {0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0}
How can I do this?
EDIT: If query's any indice has 3 or 4 value, lst2's same indice must have 0 value. If query's any indice has 3 or 4 value AND previous indice has 0 value, lst2's same indices must have 0 value. Likewise; If query's any indice has 1 or 2 value, lst2's same indice must have 1 value. If query's any indice has 1 or 2 value AND previous indice has 0 value, lst2's same indices must have 1 value.
An alternative approach, only filling the tracing 0's when needed. Performance wise it's still best to loop reversed, but I only just saw T_D already did that, so as far as the lookahead -> lookback goes, the below is basically the same, but with other syntax and a different trailing 0 filler.
var arr = new int[query.Count];
int cnt = query.Count - 1, toappendindex = -1;
Func<int,int,int> getval = (ind, val) =>
{
if (val == 3 || val == 4) return 0;
if (val == 2 || val == 1) return 1;
if (ind == cnt) return -1;
return arr[ind + 1];
};
for (int ind = cnt; ind >= 0; ind-- )
{
if ((arr[ind] = getval(ind,query[ind])) == -1)
toappendindex = ind; //only if there are trailing 0's
}
if (toappendindex > 0)
for (; toappendindex < arr.Length; toappendindex++) arr[toappendindex] = arr[toappendindex - 1];
//var lst2 = arr.ToList(); if list is needed instead of array, otherwise arr could be used directly
Try doing this.
List<int> query = Enumerable.Range(0, 1440).Select((n, index) =>
{
if ((index >= 525 && index <= 544) || (index >= 600 && index <= 749) || (index >= 810 && index <= 1079) || (index >= 1300 && index <= 1439))
return 0;
else if (index >= 1080 && index <= 1299)
return 1;
else if (index >= 545 && index <= 599)
return 3;
else if (index >= 750 && index <= 809)
return 4;
else
return 2;
}).ToList();
Console.WriteLine(string.Concat("{", string.Join(",", query.ToArray()), "}"));
List<int> lst2 = Enumerable.Range(0, 1440).Select((n, index) =>
{
if (query[index] == 1 || query[index] == 2)
return 1;
else if (query[index] == 3 || query[index] == 4)
return 0;
else
{
int retval = 1;
//look ahead
for (int i = index; i < query.Count; i++)
{
if (query[i] == 1 || query[i] == 2)
{
break;
}
if (query[i] == 3 || query[i] == 4)
{
retval = 0;
break;
}
}
return retval;
}
}).ToList();
Console.WriteLine(string.Concat("{", string.Join(",", lst2.ToArray()), "}"));
Let me know if this is what you are looking for. You can replace List with var if you like. I just like it strong-typed so that I can easily check the output.
I hope this is what you need:
int n = 1440;
byte[] query = new byte[n];
byte[] lst2 = new byte[n];
byte mode = 0;
bool first = true;
for(int index = n-1; index >= 0; index--)
{
if ((index >= 525 && index <= 544) || (index >= 600 && index <= 749) || (index >= 810 && index <= 1079) || (index >= 1300 && index <= 1439))
query[index] = 0;
else if (index >= 1080 && index <= 1299)
query[index] = 1;
else if (index >= 545 && index <= 599)
query[index] = 3;
else if (index >= 750 && index <= 809)
query[index] = 4;
else
query[index] = 2;
if(query[index] == 3 || query[index] == 4)
{
mode = 0;
lst2[index] = 0;
}
else if(query[index] == 1 || query[index] == 2)
{
if(first)
{
//change ending zeros to 1
for(int j=index+1; j < n; j++)
lst2[j] = 1;
first = false;
}
mode = 1;
lst2[index] = 1;
}
else
{
lst2[index] = mode;
}
}

Categories