fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int i, j;
  6. long dec; /* ให้รับค่าอินพุทแบบ Long Integer - เลขจำนวนเต็มแบบยาว */
  7. int bit[32]; /* จองพื้นที่ในการเก็บข้อมูลเลขฐาน 2 ลงใน Array */
  8.  
  9. clrscr(); /* เคลียร์หน้าจอ */
  10. printf("Decimal Number : "); /* แจ้งผู้ใช้เพื่อเตรียมป้อนค่าเลขฐาน 10 */
  11. scanf("%ld", &dec); /* ต้องใช้ ld เพราะ Input มันเป็นแบบ Long Integer */
  12. i = 0; /* กำหนดค่าเริ่มต้นของ Array */
  13. /* ทำตามที่ได้ออกแบบโปรแกรมเอาไว้ ... ยังไงยังงั้นเลย 55555+ */
  14. do {
  15. bit[i++] = dec % 2; /* การหารเอาเศษ เพื่อให้เป็นคำตอบ */
  16.  
  17. /* การหารทั่วไป แต่ตัวแปร dec ของภาษา C มันเป็น Integer หรือ เลขจำนวนเต็ม */
  18. /* ดังนั้นมันจึงตัดเศษ (หรือทศนิยม) ทิ้งไปโดยอัตโนมัติ */
  19. dec = dec / 2;
  20.  
  21. } while (dec > 0); /* เงื่อนไขที่ทำจนกระทั่ง dec = 0 ก็ออกจากวังวนเงื่อนไข */
  22.  
  23. /* การแสดงผลของการแปลงเลขฐาน 10 เป็นเลขฐาน 2*/
  24. /* j = i - 1 และให้ j ลดค่าลงทีละ 1 ... ก็คืออ่านข้อมูลถอยหลังกลับเท่านั้นเองครับ */
  25. /* เพราะตัวแปรแบบ Array ในภาษา C มันเก็บข้อมูลจากซ้ายไปขวา */
  26. /* ทำให้ LSB มันไปอยู่ทางซ้าย ส่วน MSB มันไปอยู่ทางขวา */
  27. for(j = i - 1; j >= 0; j--)
  28. printf("%d", bit[j]);
  29.  
  30. printf("\n");
  31. return 0;
  32.  
  33. }
  34.  
  35. const MAX_PLAYER_LEVEL = 999; const MAX_GUILD_LEVEL = 500;
  36.  
  37. class Character { constructor(name, job, gender) { this.name = name; this.job = job; this.gender = gender; this.level = 1; this.exp = 0; this.guild = null; this.inventory = []; this.quests = []; this.outfit = { head: null, body: null, legs: null, accessory: null, }; }
  38.  
  39. gainExp(amount) { this.exp += amount; while (this.exp >= this.requiredExp()) { this.levelUp(); } }
  40.  
  41. requiredExp() { return 100 + this.level * 20; }
  42.  
  43. levelUp() { if (this.level < MAX_PLAYER_LEVEL) { this.level++; this.exp = 0; console.log(${this.name} เลเวลอัพเป็น ${this.level}); } }
  44.  
  45. joinGuild(guild) { this.guild = guild; guild.addMember(this); }
  46.  
  47. changeOutfit(part, item) { if (this.outfit.hasOwnProperty(part)) { this.outfit[part] = item; console.log(${this.name} เปลี่ยนชุดส่วน ${part} เป็น ${item}); } } }
  48.  
  49. class Guild { constructor(name, founder) { this.name = name; this.level = 1; this.members = []; this.rank = 0; this.decorations = []; this.founder = founder; }
  50.  
  51. addMember(character) { this.members.push(character); }
  52.  
  53. gainGuildExp(points) { if (this.level < MAX_GUILD_LEVEL) { this.level += Math.floor(points / 100); } }
  54.  
  55. decorate(item) { this.decorations.push(item); } }
  56.  
  57. function createGuild(name, founder) { const newGuild = new Guild(name, founder); founder.joinGuild(newGuild); return newGuild; }
  58.  
  59. class Quest { constructor(name, description, requiredJob, rewardExp) { this.name = name; this.description = description; this.requiredJob = requiredJob; this.rewardExp = rewardExp; }
  60.  
  61. canAccept(character) { return this.requiredJob === null || character.job === this.requiredJob; }
  62.  
  63. complete(character) { character.gainExp(this.rewardExp); } }
  64.  
  65. class Dungeon { constructor(name, requiredLevel, bossName, rewardItems) { this.name = name; this.requiredLevel = requiredLevel; this.bossName = bossName; this.rewardItems = rewardItems; }
  66.  
  67. enter(character) { if (character.level >= this.requiredLevel) { console.log(${character.name} เข้าสู่ดันเจี้ยน ${this.name}); } else { console.log("เลเวลยังไม่ถึงสำหรับดันเจี้ยนนี้"); } } }
  68.  
  69. class Market { constructor() { this.listings = []; }
  70.  
  71. listItem(seller, item, price) { this.listings.push({ seller, item, price }); console.log(${seller.name} ลงขาย ${item} ราคา ${price} โกลด์); }
  72.  
  73. buyItem(buyer, itemName) { const index = this.listings.findIndex(l => l.item === itemName); if (index !== -1) { const listing = this.listings.splice(index, 1)[0]; buyer.inventory.push(listing.item); console.log(${buyer.name} ซื้อ ${listing.item} จาก ${listing.seller.name}); } else { console.log("ไม่พบไอเท็มในตลาด"); } } }
  74.  
  75. class ChatSystem { constructor() { this.publicChat = []; this.guildChats = {}; this.privateChats = {}; }
  76.  
  77. sendPublic(message, sender) { this.publicChat.push({ sender, message }); }
  78.  
  79. sendGuild(guild, message, sender) { if (!this.guildChats[guild.name]) this.guildChats[guild.name] = []; this.guildChats[guild.name].push({ sender, message }); }
  80.  
  81. sendPrivate(from, to, message) { const key = [from.name, to.name].sort().join("_"); if (!this.privateChats[key]) this.privateChats[key] = []; this.privateChats[key].push({ from: from.name, to: to.name, message }); } }
  82.  
  83. // === ตัวอย่างการใช้งานเบื้องต้น === const kazuki = new Character("Kazuki", "นักเวทย์", "ชาย"); const mefu = new Character("Mefu", "นักพฤกษศาสตร์", "หญิง");
  84.  
  85. const naniGuild = createGuild("Nani Dimension", kazuki);
  86.  
  87. const flowerQuest = new Quest("กลิ่นหอมของสันติ", "เก็บกลีบมูนวู้ดจากป่ามืด", "นักพฤกษศาสตร์", 500); if (flowerQuest.canAccept(mefu)) { flowerQuest.complete(mefu); }
  88.  
  89. const dungeon = new Dungeon("ถ้ำคาเมลเลีย", 40, "Arlo Vikus", ["กลีบคาเมลเลีย"]); dungeon.enter(kazuki);
  90.  
  91. kazuki.changeOutfit("head", "หมวกพ่อมดไฟ"); mefu.changeOutfit("accessory", "เข็มกลัดดอกไม้เงิน");
  92.  
  93. const market = new Market(); market.listItem(mefu, "ดอกคาเมลเลียขาว", 120); market.buyItem(kazuki, "ดอกคาเมลเลียขาว");
  94.  
  95. const chat = new ChatSystem(); chat.sendPublic("ยินดีต้อนรับผู้กล้าทุกคน!", kazuki); chat.sendGuild(naniGuild, "คืนนี้ลงดันตีบอส!", mefu); chat.sendPrivate(kazuki, mefu, "พร้อมหรือยัง?");
  96.  
  97.  
Success #stdin #stdout 0.03s 26012KB
stdin
Standard input is empty
stdout
#include <stdio.h>

int main(void)
{
int i, j;
long dec;  /* ให้รับค่าอินพุทแบบ Long Integer - เลขจำนวนเต็มแบบยาว */
int bit[32];  /* จองพื้นที่ในการเก็บข้อมูลเลขฐาน 2 ลงใน Array */

    clrscr();  /* เคลียร์หน้าจอ */
    printf("Decimal Number : ");  /* แจ้งผู้ใช้เพื่อเตรียมป้อนค่าเลขฐาน 10 */
    scanf("%ld", &dec);  /* ต้องใช้ ld เพราะ Input มันเป็นแบบ Long Integer */
    i = 0;  /* กำหนดค่าเริ่มต้นของ Array */
    /* ทำตามที่ได้ออกแบบโปรแกรมเอาไว้ ... ยังไงยังงั้นเลย 55555+ */
    do {
        bit[i++] = dec % 2;  /* การหารเอาเศษ เพื่อให้เป็นคำตอบ */

        /* การหารทั่วไป แต่ตัวแปร dec ของภาษา C มันเป็น Integer หรือ เลขจำนวนเต็ม */
        /* ดังนั้นมันจึงตัดเศษ (หรือทศนิยม) ทิ้งไปโดยอัตโนมัติ */
        dec = dec / 2;

    } while (dec > 0);  /* เงื่อนไขที่ทำจนกระทั่ง dec = 0 ก็ออกจากวังวนเงื่อนไข */

    /* การแสดงผลของการแปลงเลขฐาน 10 เป็นเลขฐาน 2*/
    /* j = i - 1 และให้ j ลดค่าลงทีละ 1 ... ก็คืออ่านข้อมูลถอยหลังกลับเท่านั้นเองครับ */
    /* เพราะตัวแปรแบบ Array ในภาษา C มันเก็บข้อมูลจากซ้ายไปขวา */
    /* ทำให้ LSB มันไปอยู่ทางซ้าย ส่วน MSB มันไปอยู่ทางขวา */
    for(j = i - 1; j >= 0; j--)
        printf("%d", bit[j]);

printf("\n");
return 0;

}

const MAX_PLAYER_LEVEL = 999; const MAX_GUILD_LEVEL = 500;

class Character { constructor(name, job, gender) { this.name = name; this.job = job; this.gender = gender; this.level = 1; this.exp = 0; this.guild = null; this.inventory = []; this.quests = []; this.outfit = { head: null, body: null, legs: null, accessory: null, }; }

gainExp(amount) { this.exp += amount; while (this.exp >= this.requiredExp()) { this.levelUp(); } }

requiredExp() { return 100 + this.level * 20; }

levelUp() { if (this.level < MAX_PLAYER_LEVEL) { this.level++; this.exp = 0; console.log(${this.name} เลเวลอัพเป็น ${this.level}); } }

joinGuild(guild) { this.guild = guild; guild.addMember(this); }

changeOutfit(part, item) { if (this.outfit.hasOwnProperty(part)) { this.outfit[part] = item; console.log(${this.name} เปลี่ยนชุดส่วน ${part} เป็น ${item}); } } }

class Guild { constructor(name, founder) { this.name = name; this.level = 1; this.members = []; this.rank = 0; this.decorations = []; this.founder = founder; }

addMember(character) { this.members.push(character); }

gainGuildExp(points) { if (this.level < MAX_GUILD_LEVEL) { this.level += Math.floor(points / 100); } }

decorate(item) { this.decorations.push(item); } }

function createGuild(name, founder) { const newGuild = new Guild(name, founder); founder.joinGuild(newGuild); return newGuild; }

class Quest { constructor(name, description, requiredJob, rewardExp) { this.name = name; this.description = description; this.requiredJob = requiredJob; this.rewardExp = rewardExp; }

canAccept(character) { return this.requiredJob === null || character.job === this.requiredJob; }

complete(character) { character.gainExp(this.rewardExp); } }

class Dungeon { constructor(name, requiredLevel, bossName, rewardItems) { this.name = name; this.requiredLevel = requiredLevel; this.bossName = bossName; this.rewardItems = rewardItems; }

enter(character) { if (character.level >= this.requiredLevel) { console.log(${character.name} เข้าสู่ดันเจี้ยน ${this.name}); } else { console.log("เลเวลยังไม่ถึงสำหรับดันเจี้ยนนี้"); } } }

class Market { constructor() { this.listings = []; }

listItem(seller, item, price) { this.listings.push({ seller, item, price }); console.log(${seller.name} ลงขาย ${item} ราคา ${price} โกลด์); }

buyItem(buyer, itemName) { const index = this.listings.findIndex(l => l.item === itemName); if (index !== -1) { const listing = this.listings.splice(index, 1)[0]; buyer.inventory.push(listing.item); console.log(${buyer.name} ซื้อ ${listing.item} จาก ${listing.seller.name}); } else { console.log("ไม่พบไอเท็มในตลาด"); } } }

class ChatSystem { constructor() { this.publicChat = []; this.guildChats = {}; this.privateChats = {}; }

sendPublic(message, sender) { this.publicChat.push({ sender, message }); }

sendGuild(guild, message, sender) { if (!this.guildChats[guild.name]) this.guildChats[guild.name] = []; this.guildChats[guild.name].push({ sender, message }); }

sendPrivate(from, to, message) { const key = [from.name, to.name].sort().join("_"); if (!this.privateChats[key]) this.privateChats[key] = []; this.privateChats[key].push({ from: from.name, to: to.name, message }); } }

// === ตัวอย่างการใช้งานเบื้องต้น === const kazuki = new Character("Kazuki", "นักเวทย์", "ชาย"); const mefu = new Character("Mefu", "นักพฤกษศาสตร์", "หญิง");

const naniGuild = createGuild("Nani Dimension", kazuki);

const flowerQuest = new Quest("กลิ่นหอมของสันติ", "เก็บกลีบมูนวู้ดจากป่ามืด", "นักพฤกษศาสตร์", 500); if (flowerQuest.canAccept(mefu)) { flowerQuest.complete(mefu); }

const dungeon = new Dungeon("ถ้ำคาเมลเลีย", 40, "Arlo Vikus", ["กลีบคาเมลเลีย"]); dungeon.enter(kazuki);

kazuki.changeOutfit("head", "หมวกพ่อมดไฟ"); mefu.changeOutfit("accessory", "เข็มกลัดดอกไม้เงิน");

const market = new Market(); market.listItem(mefu, "ดอกคาเมลเลียขาว", 120); market.buyItem(kazuki, "ดอกคาเมลเลียขาว");

const chat = new ChatSystem(); chat.sendPublic("ยินดีต้อนรับผู้กล้าทุกคน!", kazuki); chat.sendGuild(naniGuild, "คืนนี้ลงดันตีบอส!", mefu); chat.sendPrivate(kazuki, mefu, "พร้อมหรือยัง?");