ในกรณีของ string ที่ประกอบด้วย 0 และ 1 เท่านั้น เราได้รับ M ranges ที่ไม่ intersect คือ A, B (A <= B) โดยเฉพาะ [A1, B1], [A2, B2], ..., [AM, BM] ไม่มี interval ใด overlap กัน − formally สำหรับ valid i, j ที่ i!=j ไม่ว่า Ai
ในกรณีของ string ที่ประกอบด้วย 0 และ 1 เท่านั้น เราได้รับ M ranges ที่ไม่ intersect คือ A, B (A <= B) โดยเฉพาะ [A1, B1], [A2, B2], ..., [AM, BM] ไม่มี interval ใด overlap กัน − formally สำหรับ valid i, j ที่ i!=j ไม่ว่า Ai
Barabási-Albert model ถือเป็นหนึ่งในหลายโมเดลที่เสนอมาเพื่อผลิต scale-free networks มันรวม 2 แนวคิดสำคัญ: growth และ preferential attachment ทั้ง 2 แนวคิดนี้มีอยู่จริงใน real networks ความหมายของ growth คือจำนวน nodes ใน network เพิ่มขึ้นตามเวลา ความหมายของ preferential attachment คือ node ที่เชื่อ
2s Complement Number System ใช้กันอย่างแพร่หลายใน computer architecture N-bit 2s Complement number System สามารถแทนตัวเลขจาก -2^(n-1) ถึง 2^(n-1)-1 4 Bit แทนได้ -8 ถึง 7 5 Bit แทนได้ -16 ถึง 15 ใน 2s Complement System Overflow เกิดขึ้นเวลา addition เมื่อ 2 N-bit 2s Complement Numbers ถูกบวกกัน และผ
ข้อมูลสามารถถ่ายโอนระหว่างคอมพิวเตอร์ 2 เครื่องด้วย Socket programming ใน C ในกรณีนี้ ไฟล์สามารถส่งได้ง่ายด้วย User Datagram Protocol (UDP) และ simple client/server Security − จัดการโดย encryption Protocol − UDP Encryption − XOR encryption Algorithm Server เริ่มต้นและรอ filename Client ส่ง filenam
ให้ decimal number n เราต้องแปลงเป็น Roman numeral ค่า n อยู่ในช่วง 1 ถึง 4000 นี่คือ Roman Numerals บางตัว Number Numeral 1I 4IV 5V 9IX 10X 40XL 50L 90XC 100C 400CD 500D 900CM 1000M 4000MMMM เช่น n = 859 Roman Numeral จะเป็น DCCCLIX เพื่อแก้ปัญหานี้ เราทำตามขั้นตอน Define array เก็บ numer
ที่นี่ เราจะดูโค้ดที่พิมพ์ 2D matrix ใน C/C++ โดยไม่ใช้ curly braces Curly braces คือ separators ใน programming language ใช้ define separate code blocks โดยไม่มี curly braces การกำหนด scope ยากใน C/C++ มาดู basic code และ sample output สำหรับพิมพ์ 2D matrix ตัวอย่าง #include <iostream> using
ที่นี่ เราต้องพิมพ์ลำดับ 1 2 3 ซ้ำๆ จำนวนครั้งไม่จำกัดโดยใช้ threads ใน C มาดู sample output ที่เราต้องการ 1 2 3 1 2 3 1 2 3 1 2 3 สำหรับนี้ เราต้องใช้ 3 threads ที่รันพร้อมกันใน C และตัวแปรที่ initialize เป็น 1 ใน thread แรก ค่าจะ update ตามค่าล่าสุด และรัน infinite loop ในฟังก์ชัน ตัวอย่าง มาดูโป
ในปัญหานี้ เราได้รับ string password งานของเราคือพิมพ์ * แทนตัวอักษรของ password มาดูตัวอย่างเพื่อเข้าใจปัญหา Input: password Output ******** เพื่อแก้ปัญหานี้ เราจะ traverse password ที่ป้อนเข้าไปและพิมพ์ * แทนตัวอักษรของ password ตัวอย่าง โปรแกรมด้านล่างจะแสดงการนำไปใช้ของวิธีแก้ของเรา #include &l
Identifier คือชื่อที่ให้กับ entity ในโปรแกรมมิ่งเพื่อระบุตัวตนในโปรแกรม โดยทั่วไป identifiers ถูกสร้างโดยโปรแกรมเมอร์ แต่มี predefined identifiers ที่ built-in อยู่ เช่น cout, cin เป็นต้น ที่นี่ เราจะดู predefined identifier หนึ่งของ C programming language คือ __func__ นิยามทางการของ __func__ คือ −
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจว่า arrays ถูกส่งให้ functions อย่างไร ใน C/C++ arrays ถูกส่งให้ function ในรูปแบบ pointer ซึ่งให้ address ของ first element ของ array ตัวอย่าง #include <stdio.h> //passing array as a pointer void fun(int arr[]){ unsigned int n = sizeof(arr)/si
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจว่า vectors ทำงานอย่างไรใน C/C++ Vector data structure เป็นการปรับปรุงจาก standard arrays ต่างจาก arrays ที่มีขนาดคงที่เมื่อ define vectors สามารถ resize ได้ง่ายตามความต้องการ สิ่งนี้ให้ความยืดหยุ่นและลดเวลาที่ arrays ต้อง copy elements ไป array ใหม่ ตัว
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจวิธีเพิ่ม graphics.h C/C++ library ให้ gcc compiler ใน Linux ต้อง compile และ install libgraph package รวมถึง install build-essential และ external packages >>sudo apt-get install build-essential >>sudo apt-get install libsdl-image1.2 libsdl-i
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจวิธีพิมพ์ semicolon(;) โดยไม่ใช้ semicolon ใน C/C++ ทำได้ 2 วิธี คือใช้ ASCII value ของ semicolon หรือใช้ user-defined macros ตัวอย่าง ใช้ putchar() method #include <stdio.h> int main(){ //ASCII value of semicolon is equal to 59 if (putchar
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจวิธีบวกจำนวนเต็ม 2 จำนวนโดยไม่ใช้ arithmetic operators ใน C/C++ สำหรับการบวก 2 จำนวนเต็มโดยไม่ใช้ arithmetic operators เราสามารถทำได้ด้วย pointers หรือ bitwise operators ตัวอย่าง ใช้ pointers #include <iostream> using namespace std; int sum(int a,
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจ thread functions ใน C/C++ Thread functions อนุญาตให้ผู้ใช้ implement concurrent functions พร้อมกัน ซึ่งอาจ dependent หรือ independent กัน ตัวอย่าง #include <pthread.h> #include <stdio.h> #include <stdlib.h> void* func(void* arg){ /
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจ continue statement ใน C/C++ Continue statement เป็น loop control statement ที่แทนที่จะ break ออกจากลูปเหมือน break statement จะบังคับให้ pointer ปัจจุบันไปยัง iteration ถัดไปของลูปโดยไม่ execute statements ที่เหลือใน iteration ปัจจุบัน ตัวอย่าง #include
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจวิธีแปลง string เป็น integer array ใน C/C++ สำหรับนี้ เราจะสร้างอาร์เรย์ใหม่ วนลูปผ่าน string ที่ให้มา ถ้าตัวอักษรคือ comma , ให้ข้ามไปตัวถัดไป ไม่เช่นนั้นเพิ่มเข้าไปในอาร์เรย์ใหม่ ตัวอย่าง #include <bits/stdc++.h> using namespace std; //converting
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจวิธีแปลง strings เป็น numbers ใน C/C++ C/C++ มี 2 วิธีในการแปลง strings เป็น numbers ตัวอย่าง ใช้ sscanf() #include<stdio.h> int main(){ const char *str = 12345; int x; sscanf(str, %d, &x); printf(\nThe value of x : %d, x); retu
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจ core dump (segmentation fault) ใน C/C++ มันเกิดจากเหตุผลเช่น โค้ดพยายามเขียนบน read-only memory หรือพยายาม access corrupt memory location ตัวอย่าง Modifying a string literal int main(){ char *str; str = GfG; *(str+1) = n; return 0; } Acc
ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมสร้าง directory หรือ folder ด้วย C/C++ program เพื่อสร้าง directory ใหม่ เราจะใช้คำสั่ง mkdir() โค้ดนี้ทำงานได้เฉพาะ Windows compiler เท่านั้น ตัวอย่าง #include <conio.h> #include <dir.h> #include <process.h> #include <stdio.h> void main(){