commit d64480ab36fb21bb7e34d778368341c49c8880fa
parent 97581b16abf720b34db3a4d38465d774622b6c20
Author: Amit Dutta <amitdutta4255@gmail.com>
Date: Sun, 25 Jan 2026 16:05:45 +0530
[2026-01-25] : .\Semester_1\challenge : added classmate given code
Diffstat:
3 files changed, 386 insertions(+), 28 deletions(-)
diff --git a/Semester_1/challenge/maheswar01.c b/Semester_1/challenge/maheswar01.c
@@ -0,0 +1,185 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#define MAX 1000
+
+/* ================= STACK FOR OPERATORS ================= */
+
+typedef struct {
+ char data[MAX];
+ int top;
+} CharStack;
+
+void initCharStack(CharStack *s) {
+ s->top = -1;
+}
+
+void pushChar(CharStack *s, char c) {
+ s->data[++s->top] = c;
+}
+
+char popChar(CharStack *s) {
+ return s->data[s->top--];
+}
+
+char peekChar(CharStack *s) {
+ return s->data[s->top];
+}
+
+int isEmptyChar(CharStack *s) {
+ return s->top == -1;
+}
+
+/* ================= STACK FOR NUMBERS ================= */
+
+typedef struct {
+ double data[MAX];
+ int top;
+} DoubleStack;
+
+void initDoubleStack(DoubleStack *s) {
+ s->top = -1;
+}
+
+void pushDouble(DoubleStack *s, double x) {
+ s->data[++s->top] = x;
+}
+
+double popDouble(DoubleStack *s) {
+ return s->data[s->top--];
+}
+
+/* ================= HELPER FUNCTIONS ================= */
+
+int precedence(char op) {
+ if (op == '+' || op == '-') return 1;
+ if (op == '*' || op == '/') return 2;
+ return 0;
+}
+
+int isOperator(char c) {
+ return c == '+' || c == '-' || c == '*' || c == '/';
+}
+
+/* ================= INFIX TO POSTFIX ================= */
+
+void infixToPostfix(const char *infix, char *postfix) {
+ CharStack stack;
+ initCharStack(&stack);
+
+ int i = 0, k = 0;
+
+ while (infix[i]) {
+ if (isspace(infix[i])) {
+ i++;
+ continue;
+ }
+
+ if (isdigit(infix[i]) || infix[i] == '.') {
+ while (isdigit(infix[i]) || infix[i] == '.') {
+ postfix[k++] = infix[i++];
+ }
+ postfix[k++] = ' ';
+ }
+ else if (infix[i] == '(') {
+ pushChar(&stack, infix[i]);
+ i++;
+ }
+ else if (infix[i] == ')') {
+ while (!isEmptyChar(&stack) && peekChar(&stack) != '(') {
+ postfix[k++] = popChar(&stack);
+ postfix[k++] = ' ';
+ }
+ popChar(&stack); // remove '('
+ i++;
+ }
+ else if (isOperator(infix[i])) {
+ while (!isEmptyChar(&stack) &&
+ precedence(peekChar(&stack)) >= precedence(infix[i])) {
+ postfix[k++] = popChar(&stack);
+ postfix[k++] = ' ';
+ }
+ pushChar(&stack, infix[i]);
+ i++;
+ }
+ else {
+ printf("Invalid character: %c\n", infix[i]);
+ exit(1);
+ }
+ }
+
+ while (!isEmptyChar(&stack)) {
+ postfix[k++] = popChar(&stack);
+ postfix[k++] = ' ';
+ }
+
+ postfix[k] = '\0';
+}
+
+/* ================= POSTFIX EVALUATION ================= */
+
+double evaluatePostfix(const char *postfix) {
+ DoubleStack stack;
+ initDoubleStack(&stack);
+
+ int i = 0;
+
+ while (postfix[i]) {
+ if (isspace(postfix[i])) {
+ i++;
+ continue;
+ }
+
+ if (isdigit(postfix[i]) || postfix[i] == '.') {
+ char number[50];
+ int k = 0;
+
+ while (isdigit(postfix[i]) || postfix[i] == '.') {
+ number[k++] = postfix[i++];
+ }
+ number[k] = '\0';
+
+ pushDouble(&stack, atof(number));
+ }
+ else if (isOperator(postfix[i])) {
+ double b = popDouble(&stack);
+ double a = popDouble(&stack);
+
+ switch (postfix[i]) {
+ case '+': pushDouble(&stack, a + b); break;
+ case '-': pushDouble(&stack, a - b); break;
+ case '*': pushDouble(&stack, a * b); break;
+ case '/':
+ if (b == 0) {
+ printf("Error: Division by zero\n");
+ exit(1);
+ }
+ pushDouble(&stack, a / b);
+ break;
+ }
+ i++;
+ }
+ }
+
+ return popDouble(&stack);
+}
+
+/* ================= MAIN ================= */
+
+int main() {
+ char infix[MAX];
+ char postfix[MAX];
+
+ printf("Enter expression: ");
+ fgets(infix, MAX, stdin);
+
+ infixToPostfix(infix, postfix);
+
+ double result = evaluatePostfix(postfix);
+
+ printf("Result = %.10g\n", result);
+
+ return 0;
+}+
\ No newline at end of file
diff --git a/Semester_1/challenge/sudiptoown01.c b/Semester_1/challenge/sudiptoown01.c
@@ -1,18 +1,4 @@
/*
- * ======================================================================================
- * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
- * Repository : https://github.com/notamitgamer/bsc
- * License : ESAL-1.0 ( https://esal.amit.is-a.dev/ )
- * ======================================================================================
- * [ ACADEMIC INTEGRITY WARNING ]
- * The use of this code for academic assignments at ANY educational institution,
- * college, or university is STRICTLY PROHIBITED.
- * Any other use requires prior written permission from the author.
- * Violations will be reported as academic misconduct.
- * ======================================================================================
- */
-
-/*
* A smart home security controller monitors the state of several sensors to decide what action to take.
* Each second, the system reads data from sensors that are either an active or inactive. Based on the current
* state of all sensors, the controller must perform exactly one action, such as activating a warning, checking
diff --git a/docs/index.html b/docs/index.html
@@ -4766,6 +4766,206 @@ int main()
<div class="hidden pl-4 mt-1 border-l-2 border-slate-100 ml-3.5">
<div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
+ <div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-challenge-maheswar01-c', 'maheswar01.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/challenge/maheswar01.c')">
+ <svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
+ </svg>
+ <span class="text-sm text-slate-600 font-medium group-hover:text-blue-600 truncate">maheswar01.c</span>
+ </div>
+ <div class="flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
+ <a href="https://github.com/notamitgamer/bsc/blob/main/Semester_1/challenge/maheswar01.c" target="_blank" class="p-1.5 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded-md" title="View on GitHub">
+ <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24"><path fill-rule="evenodd" d="M12 2C6.477 2 2 6.484 2 12.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-2.126 1.029-2.935-.103-.253-.446-1.372.097-2.897 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0112 6.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.525.202 2.644.1 2.897.64.809 1.026 1.841 1.026 2.935 0 3.847-2.337 4.687-4.565 4.935.359.309.678.92.678 1.855 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0022 12.017C22 6.484 17.522 2 12 2z" clip-rule="evenodd"></path></svg>
+ </a>
+ </div>
+ <!-- Embedded Code Storage -->
+ <div id="code-Semester_1-challenge-maheswar01-c" style="display:none;">#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+#define MAX 1000
+
+/* ================= STACK FOR OPERATORS ================= */
+
+typedef struct {
+ char data[MAX];
+ int top;
+} CharStack;
+
+void initCharStack(CharStack *s) {
+ s->top = -1;
+}
+
+void pushChar(CharStack *s, char c) {
+ s->data[++s->top] = c;
+}
+
+char popChar(CharStack *s) {
+ return s->data[s->top--];
+}
+
+char peekChar(CharStack *s) {
+ return s->data[s->top];
+}
+
+int isEmptyChar(CharStack *s) {
+ return s->top == -1;
+}
+
+/* ================= STACK FOR NUMBERS ================= */
+
+typedef struct {
+ double data[MAX];
+ int top;
+} DoubleStack;
+
+void initDoubleStack(DoubleStack *s) {
+ s->top = -1;
+}
+
+void pushDouble(DoubleStack *s, double x) {
+ s->data[++s->top] = x;
+}
+
+double popDouble(DoubleStack *s) {
+ return s->data[s->top--];
+}
+
+/* ================= HELPER FUNCTIONS ================= */
+
+int precedence(char op) {
+ if (op == '+' || op == '-') return 1;
+ if (op == '*' || op == '/') return 2;
+ return 0;
+}
+
+int isOperator(char c) {
+ return c == '+' || c == '-' || c == '*' || c == '/';
+}
+
+/* ================= INFIX TO POSTFIX ================= */
+
+void infixToPostfix(const char *infix, char *postfix) {
+ CharStack stack;
+ initCharStack(&stack);
+
+ int i = 0, k = 0;
+
+ while (infix[i]) {
+ if (isspace(infix[i])) {
+ i++;
+ continue;
+ }
+
+ if (isdigit(infix[i]) || infix[i] == '.') {
+ while (isdigit(infix[i]) || infix[i] == '.') {
+ postfix[k++] = infix[i++];
+ }
+ postfix[k++] = ' ';
+ }
+ else if (infix[i] == '(') {
+ pushChar(&stack, infix[i]);
+ i++;
+ }
+ else if (infix[i] == ')') {
+ while (!isEmptyChar(&stack) && peekChar(&stack) != '(') {
+ postfix[k++] = popChar(&stack);
+ postfix[k++] = ' ';
+ }
+ popChar(&stack); // remove '('
+ i++;
+ }
+ else if (isOperator(infix[i])) {
+ while (!isEmptyChar(&stack) &&
+ precedence(peekChar(&stack)) >= precedence(infix[i])) {
+ postfix[k++] = popChar(&stack);
+ postfix[k++] = ' ';
+ }
+ pushChar(&stack, infix[i]);
+ i++;
+ }
+ else {
+ printf("Invalid character: %c\n", infix[i]);
+ exit(1);
+ }
+ }
+
+ while (!isEmptyChar(&stack)) {
+ postfix[k++] = popChar(&stack);
+ postfix[k++] = ' ';
+ }
+
+ postfix[k] = '\0';
+}
+
+/* ================= POSTFIX EVALUATION ================= */
+
+double evaluatePostfix(const char *postfix) {
+ DoubleStack stack;
+ initDoubleStack(&stack);
+
+ int i = 0;
+
+ while (postfix[i]) {
+ if (isspace(postfix[i])) {
+ i++;
+ continue;
+ }
+
+ if (isdigit(postfix[i]) || postfix[i] == '.') {
+ char number[50];
+ int k = 0;
+
+ while (isdigit(postfix[i]) || postfix[i] == '.') {
+ number[k++] = postfix[i++];
+ }
+ number[k] = '\0';
+
+ pushDouble(&stack, atof(number));
+ }
+ else if (isOperator(postfix[i])) {
+ double b = popDouble(&stack);
+ double a = popDouble(&stack);
+
+ switch (postfix[i]) {
+ case '+': pushDouble(&stack, a + b); break;
+ case '-': pushDouble(&stack, a - b); break;
+ case '*': pushDouble(&stack, a * b); break;
+ case '/':
+ if (b == 0) {
+ printf("Error: Division by zero\n");
+ exit(1);
+ }
+ pushDouble(&stack, a / b);
+ break;
+ }
+ i++;
+ }
+ }
+
+ return popDouble(&stack);
+}
+
+/* ================= MAIN ================= */
+
+int main() {
+ char infix[MAX];
+ char postfix[MAX];
+
+ printf("Enter expression: ");
+ fgets(infix, MAX, stdin);
+
+ infixToPostfix(infix, postfix);
+
+ double result = evaluatePostfix(postfix);
+
+ printf("Result = %.10g\n", result);
+
+ return 0;
+}</div>
+ </div>
+
+ <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">
<div class="flex items-center gap-2.5 min-w-0 cursor-pointer flex-1" onclick="showCode('code-Semester_1-challenge-sudipto1-c', 'sudipto1.c', 'https://github.com/notamitgamer/bsc/blob/main/Semester_1/challenge/sudipto1.c')">
<svg class="w-4 h-4 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
@@ -4960,20 +5160,6 @@ int main()
</div>
<!-- Embedded Code Storage -->
<div id="code-Semester_1-challenge-sudiptoown01-c" style="display:none;">/*
- * ======================================================================================
- * COPYRIGHT (C) 2025 AMIT DUTTA. ALL RIGHTS RESERVED.
- * Repository : https://github.com/notamitgamer/bsc
- * License : ESAL-1.0 ( https://esal.amit.is-a.dev/ )
- * ======================================================================================
- * [ ACADEMIC INTEGRITY WARNING ]
- * The use of this code for academic assignments at ANY educational institution,
- * college, or university is STRICTLY PROHIBITED.
- * Any other use requires prior written permission from the author.
- * Violations will be reported as academic misconduct.
- * ======================================================================================
- */
-
-/*
* A smart home security controller monitors the state of several sensors to decide what action to take.
* Each second, the system reads data from sensors that are either an active or inactive. Based on the current
* state of all sensors, the controller must perform exactly one action, such as activating a warning, checking