static void Main(string[] args)
{
Console.WriteLine("Введите n:");
int n = Int32.Parse(Console.ReadLine());
//Строим матрицу
int[,] mx = new int[n,n];
bool invert = true;
for (int i = 0, c = 1; i < n; i++) {
for (int j = 0; j < n; j++,c++) {
int inx = invert ? n - j - 1: j;
mx[inx, i] = c;
}
invert = !invert;
}
//Выводим
int maxWidth = (n * n).ToString().Length;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
sb.Append(mx[i, j]).Append(' ', maxWidth - mx[i, j].ToString().Length+1);
sb.AppendLine();
}
Console.WriteLine(sb);
Console.ReadKey();
}
static void Main(string[] args)
{
CustomPackage cp = new CustomPackage();
cp.offset = 3;
cp.state = true;
cp.latitude = new BitArray(23);
cp.latitude.SetAll(true);
cp.longitude= new BitArray(24);
cp.longitude.SetAll(false);
cp.height= new BitArray(24);
cp.height.SetAll(true);
cp.speedNS= new BitArray(11);
cp.speedNS.SetAll(true);
cp.speedWE = new BitArray(11);
cp.speedWE.SetAll(true);
var bytes = cp.toBytes();//Пакет в байты
var p = CustomPackage.FromBytes(bytes);//Пакет из байтов
}
}
public class CustomPackage{
public int offset;// 4 байта смещения
public bool state;//1 бит - состояние
public BitArray latitude = new BitArray(23);//23 бита - широта,
public BitArray longitude = new BitArray(24);//24 бита - долгота
public BitArray height = new BitArray(12);//12 бит - высота
// 7 бит пропускаем,
public BitArray speedNS = new BitArray(11);// 11 бит - скорость относительно оси север-юг,
public BitArray speedWE = new BitArray(11);//11 бит - скорость относительно оси запад-восток.
public static CustomPackage FromBytes(byte[] arr){
CustomPackage cp = new CustomPackage();
BitArray bt = new BitArray(arr);
int ptr = 0;
cp.offset = BitConverter.ToInt32(arr, ptr);
ptr += 32;
cp.state = bt[ptr++];
cp.latitude = cp.utilCopyBits(bt, ptr, 23);
ptr += 23;
cp.longitude= cp.utilCopyBits(bt, ptr, 24);
ptr += 24;
cp.height= cp.utilCopyBits(bt, ptr, 12);
ptr += 12;
ptr += 7;
cp.speedNS= cp.utilCopyBits(bt, ptr, 11);
ptr += 11;
cp.speedWE= cp.utilCopyBits(bt, ptr, 11);
return cp;
}
public byte[] toBytes(){
byte[] buff = new byte[16];
int ptr = 0;
utilWrite(ref ptr, ref buff, new BitArray(BitConverter.GetBytes(offset)),32);
utilWrite(ref ptr, ref buff, new BitArray(BitConverter.GetBytes(state)), 1);
utilWrite(ref ptr, ref buff, latitude,23);
utilWrite(ref ptr, ref buff, longitude,24);
utilWrite(ref ptr, ref buff, height,12);
ptr += 7;// 7 бит пропускаем
utilWrite(ref ptr, ref buff, speedNS, 11);
utilWrite(ref ptr, ref buff, speedWE, 11);
return buff;
}
private BitArray utilCopyBits(BitArray source, int offset, int length)
{
BitArray b = new BitArray(length);
for (int i = 0; i < length; i++)
b[i] = source[offset + i];
return b;
}
private void utilWrite(ref int ptr, ref byte[] buff, BitArray writeData, int writeBitLength){
BitArray bt = new BitArray(buff);
for (int i = 0; i < writeBitLength; i++)
bt.Set(ptr++, writeData[i]);
bt.CopyTo(buff,0);
}
}
Console.WriteLine(getCount(moves,Figure.Queen));
//....
public int getCount(List<Coords>[][,] arr, Figure figure)
{
int count = 0;
foreach (var c in arr[(int) figure])
count += c.Count;
return count;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
const double scale = 0.35;
const int depth = 5;
public MainWindow()
{
InitializeComponent();
btnStart_Click(null, null);
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
double xmid = image.Width / 2;
double ymid = image.Height / 2;
DrawStar(1, xmid, ymid, 100, -1);
}
private void DrawStar(int level, double x, double y, double r, int skip, bool isRotate = true){
double offset = isRotate? Math.PI / 2:-Math.PI / 2;
const double angle = 4 * Math.PI / 5;
Polyline star = new Polyline();
star.Stroke = Brushes.DarkRed;
image.Children.Add(star);
for (int i = 0; i <= 5; i++){
var angleT = offset + i * angle;
var lx = (int) (x + r*Math.Cos(angleT));
var ly = (int) (y + r*Math.Sin(angleT));
star.Points.Add(new Point(lx,ly));
if (level < depth){
var newrad = r*scale;
var lx2 = (int)(x + (r + newrad) * Math.Cos(angleT));
var ly2 = (int)(y + (r + newrad) * Math.Sin(angleT));
if(i != skip && i !=5)
DrawStar(level + 1, lx2, ly2, newrad, i, !isRotate);
}
}
}
}
}
public static void UzipOneFile(string zipPath, string directoryOutPath) {
var outDir = new DirectoryInfo(directoryOutPath);
if (!outDir.Exists)
outDir.Create();
var archFile = new FileInfo(zipPath);
if(!archFile.Exists)
return;
using (var f = File.Open(archFile.FullName, FileMode.Open)){
System.IO.Compression.ZipArchive arch = new ZipArchive(f, ZipArchiveMode.Read);
if (arch.Entries.Count > 0){
using (Stream sr = arch.Entries[0].Open()){
var ext = "";
try{
ext = new FileInfo(arch.Entries[0].Name).Extension;
}
catch (Exception){}
using (Stream sw = File.Create(outDir.FullName + "\\" + archFile.Name+ext)){
while (true){
int data = sr.ReadByte();
if(data == -1)
break;
sw.WriteByte((byte) data);
}
}
}
}
}
}
//...
UzipOneFile(@"D:\myarch.zip", @"D:\outFolder");
API-keys are passed into the Rest API via the X-MBX-APIKEY header.
curl -H "X-MBX-APIKEY: vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" -X POST 'https://api.binance.com/api/v3/order?symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000×tamp=1499827319559&signature=c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71'
Console.WriteLine(File.ReadAllLines(@"D:\\nums.txt").Select(s => Convert.ToDouble(s)).Sum());
string WRitePath = @"";
string line;
decimal Sum = 0;
StreamReader sr = new StreamReader(WRitePath, System.Text.Encoding.Default);
while ((line = sr.ReadLine()) != null)
{
decimal number = Convert.ToDecimal(line);
Sum+= number;
}
sr.Close();
Console.WriteLine(Sum);
Console.ReadKey();
struct SEmployee
{
public string name;
}
static List<List<SEmployee>> InputBregEmployee()
{
List<List<SEmployee>> Lemployees = new List<List<SEmployee>>();
Console.WriteLine("Введите количество бригад");
int brigade = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i <= brigade - 1; i++) {
Console.WriteLine("Введите количество сотрудников в " + (i+1) + " бригаде");
int employee = Convert.ToInt32(Console.ReadLine());
var employees = new List<SEmployee>();
for (int t = 0; t <= employee - 1; t++) {
Console.WriteLine("Введите имя сотрудника");
employees.Add(new SEmployee() {name = Console.ReadLine() });
}
Lemployees.Add(employees);
}
return Lemployees;
}
public IQueryable<T> applyFilter<T>(IQueryable<T> source, List<string> fieldsSearch, object searchValue){
var propertyNames = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => fieldsSearch.Contains(p.Name));
return source.Where(new Func<T, bool>(s =>
{
foreach (var propertyName in propertyNames){
var v = propertyName.GetValue(s, null);
if (v != null && v.ToString().Contains(searchValue.ToString()))
return true;
}
return false;
})).AsQueryable();
}
(1 / 3)
(1f/ 3f)
private static object locker = new object();
private async Task checkFile(string path)
{
var fileType = await getFileAsync(path);
if (fileType.FileExtension != "None")
{
lock(locker){
this.filesMap.Add(path, fileType);
}
}
}
private void button3_Click(object sender, EventArgs e) {//Шифруем текст в файл
string textDecode = textBox2.Text;
byte[] bytes = Encoding.UTF8.GetBytes(textDecode);
int wh = (int) Math.Ceiling(Math.Sqrt(Math.Ceiling((double) ((bytes.Length + 4)/3))));//Определяем размер изображения для шифрования, + 4 (4 байта для резервируем в начале для записи размера массива bytes), делим на три потому что RGB, тоесть в 1 пиксель может 3 байта всунуть
Bitmap img = new Bitmap(wh,wh);
byte[] length = BitConverter.GetBytes(bytes.Length);
//пишем длинну массива
img.SetPixel(0,0,Color.FromArgb(length[0], length[1], length[2]));
img.SetPixel(1,0,Color.FromArgb(length[3], 0,0));
//пишем шифрованный текст
int cur = 0;
for (int y = 0; y < img.Height; y++) {
for (int x = 0; x < img.Width && cur < bytes.Length; x++) {
if (y == 0 && x == 0) {
x = 1;
continue;
}
byte[] pixels = new byte[]{0,0,0};
for (int k = 0; k < 3 && cur < bytes.Length; k++)
pixels[k] = bytes[cur++];
img.SetPixel(x,y,Color.FromArgb(pixels[0], pixels[1], pixels[2]));
}
}
SaveFileDialog saveFile = new SaveFileDialog();
saveFile.Filter = "Image Files (*.png, *.jpg) | *.png; *.jpg";
saveFile.InitialDirectory = @"C:\";
if (saveFile.ShowDialog() == DialogResult.OK) {
textBox1.Text = saveFile.FileName.ToString();
img.Save(textBox1.Text);
pictureBox1.ImageLocation = textBox1.Text;
}
}
private void button2_Click(object sender, EventArgs e) {//Дешифруем текст из файла
if (pictureBox1.Image == null) {
MessageBox.Show("Изображение не выбрано");
return;
}
Bitmap img = new Bitmap(pictureBox1.Image);
int length = BitConverter.ToInt32(new byte[] {//Получаем длинну массива
img.GetPixel(0,0).R,
img.GetPixel(0,0).G,
img.GetPixel(0,0).B,
img.GetPixel(1,0).R
},0);
byte[] textBytes = new byte[length];
//читаем шифрованный текст
int cur = 0;
for (int y = 0; y < img.Height; y++) {
for (int x = 0; x < img.Width && cur < textBytes.Length; x++) {
if (y == 0 && x == 0) {
x = 1;
continue;
}
for (int k = 0; k < 3 && cur < textBytes.Length; k++)
textBytes[cur++] = (new byte[] {img.GetPixel(x, y).R, img.GetPixel(x, y).G, img.GetPixel(x, y).B}[k]);
}
}
string text = Encoding.UTF8.GetString(textBytes);
textBox2.Text = text;
}
App.Current.MainWindow.Close();
string filter = "";
if (filterCountryPanel.SelectedIndex != 0)
filter = string.Format("country = '{0}'", filterCountryPanel.SelectedItem.ToString());
if (filterGenrePanel.SelectedIndex != 0)
filter += (filter == "" ? "" : " and ") + string.Format("genre = '{0}'", filterGenrePanel.SelectedItem.ToString());
(listRadioStation.DataSource as DataTable).DefaultView.RowFilter = filter == ""?null:filter;