Sandeep
// { Driver Code Starts #include<bits/stdc++.h> using namespace std; // } Driver Code Ends class Solution { public: string FirstNonRepeating(string A){ // Code here } }; // { Driver Code Starts. int main(){ int tc; cin >> tc; while(tc--){ string A; cin >> A; Solution obj; string ans = obj.FirstNonRepeating(A); cout << ans << "\n"; } return 0; } // } Driver Code Ends
Sandeep
May i ask what are oops?
Implement linked list using object oriented programming language
Sandeep
May i ask what are oops?
I'm sorry I'm not sure if I'm asking the right question..
M
#include<iostream> #include<stdlib.h> #include<ctype.h> #include<string.h> #define SIZE 50 using namespace std; struct STACK { char a [SIZE]; int top; }; typedef stuct STACK stack; void initialize (stack*s); void push (stack*s,char token); char pop (stack*s); int priority (char token); void intopost (stack*s,char infix[]); int main { char infix [SIZE]; stack s; system("CLS"); cout<<"\n\n Enter infix expression:"; cin>>infix; intopost(&s,infix); return 0; } void initialize(stack*s) { s->top= -1; } void push(stack*s,char token) { if(s->top!=SIZE-1) { s->top++; s->a[s->top]=token; } } char pop (stack*s) { char token; if(s->top!=-1) { token=s->a[s->top]; s->top--; return token; } return 0; } { int pri; switch(token) { case'^': pri=3; break; case'*': case'/': case'%': pri=2 break; case'+': case'-': pri=1; break; pri=0; default: } return pri; } { char postfix[SIZE],token; int i=0; j=0; length=0; initialize(s); push(s,'#'); length=strlen(infix); for(i=0; i<length; i++) { if(token=='(') { push(s,token); } else if (isalnum(token)) { postfix[j]=token; j++; } else if (token==')') { while(s->a[s->top]!='(') { postfix[j]=token; j++; } s->top--; } else { while(priority(s->a[s->top])>= priority(token)) { postfix[j]=pop(s); j++; } push(s,token); } while((token=pop(s))!='#') { postfix[j]= token; j++; } postfix[j]='10'; cout<<"\n\n The postfix Expression is"<<postfix; }
M
Can you solve the bugs 👆
Sandeep
May i ask what are oops?
// A C++ program to find first // non-repeating character // from a stream of characters #include <iostream> #define MAX_CHAR 256 using namespace std; // A linked list node struct node { char a; struct node *next, *prev; }; // A utility function to append a character x at the end // of DLL. Note that the function may change head and tail // pointers, that is why pointers to these pointers are // passed. void appendNode(struct node** head_ref, struct node** tail_ref, char x) { struct node* temp = new node; temp->a = x; temp->prev = temp->next = NULL; if (*head_ref == NULL) { *head_ref = *tail_ref = temp; return; } (*tail_ref)->next = temp; temp->prev = *tail_ref; *tail_ref = temp; } // A utility function to remove a node 'temp' from DLL. // Note that the function may change the head and tail pointers, // that is why pointers to these pointers are passed. void removeNode(struct node** head_ref, struct node** tail_ref, struct node* temp) { if (*head_ref == NULL) return; if (*head_ref == temp) *head_ref = (*head_ref)->next; if (*tail_ref == temp) *tail_ref = (*tail_ref)->prev; if (temp->next != NULL) temp->next->prev = temp->prev; if (temp->prev != NULL) temp->prev->next = temp->next; delete (temp); } void findFirstNonRepeating() { // inDLL[x] contains pointer to // a DLL node if x is present // in DLL. If x is not present, then inDLL[x] is NULL struct node* inDLL[MAX_CHAR]; // repeated[x] is true if x is repeated two or more // times. If x is not seen so far or x is seen only // once. then repeated[x] is false bool repeated[MAX_CHAR]; // Initialize the above two arrays struct node *head = NULL, *tail = NULL; for (int i = 0; i < MAX_CHAR; i++) { inDLL[i] = NULL; repeated[i] = false; } // Let us consider following stream and see the process char stream[] = "geeksforgeeksandgeeksquizfor"; for (int i = 0; stream[i]; i++) { char x = stream[i]; cout << "Reading " << x << " from stream \n"; // We process this character only if it has not // occurred or occurred only once. repeated[x] is // true if x is repeated twice or more.s if (!repeated[x]) { // If the character is not in DLL, then add this // at the end of DLL. if (inDLL[x] == NULL) { appendNode(&head, &tail, stream[i]); inDLL[x] = tail; } else // Otherwise remove this character from DLL { removeNode(&head, &tail, inDLL[x]); inDLL[x] = NULL; repeated[x] = true; // Also mark it as repeated } } // Print the current first non-repeating character // from stream if (head != NULL) cout << "First non-repeating character so far " "is " << head->a << endl; } } /* Driver code */ int main() { findFirstNonRepeating(); return 0; }
Sandeep
// A C++ program to find first // non-repeating character // from a stream of characters #include <iostream> #define MAX_CHAR 256 using namespace std; // A linked list node struct node { char a; struct node *next, *prev; }; // A utility function to append a character x at the end // of DLL. Note that the function may change head and tail // pointers, that is why pointers to these pointers are // passed. void appendNode(struct node** head_ref, struct node** tail_ref, char x) { struct node* temp = new node; temp->a = x; temp->prev = temp->next = NULL; if (*head_ref == NULL) { *head_ref = *tail_ref = temp; return; } (*tail_ref)->next = temp; temp->prev = *tail_ref; *tail_ref = temp; } // A utility function to remove a node 'temp' from DLL. // Note that the function may change the head and tail pointers, // that is why pointers to these pointers are passed. void removeNode(struct node** head_ref, struct node** tail_ref, struct node* temp) { if (*head_ref == NULL) return; if (*head_ref == temp) *head_ref = (*head_ref)->next; if (*tail_ref == temp) *tail_ref = (*tail_ref)->prev; if (temp->next != NULL) temp->next->prev = temp->prev; if (temp->prev != NULL) temp->prev->next = temp->next; delete (temp); } void findFirstNonRepeating() { // inDLL[x] contains pointer to // a DLL node if x is present // in DLL. If x is not present, then inDLL[x] is NULL struct node* inDLL[MAX_CHAR]; // repeated[x] is true if x is repeated two or more // times. If x is not seen so far or x is seen only // once. then repeated[x] is false bool repeated[MAX_CHAR]; // Initialize the above two arrays struct node *head = NULL, *tail = NULL; for (int i = 0; i < MAX_CHAR; i++) { inDLL[i] = NULL; repeated[i] = false; } // Let us consider following stream and see the process char stream[] = "geeksforgeeksandgeeksquizfor"; for (int i = 0; stream[i]; i++) { char x = stream[i]; cout << "Reading " << x << " from stream \n"; // We process this character only if it has not // occurred or occurred only once. repeated[x] is // true if x is repeated twice or more.s if (!repeated[x]) { // If the character is not in DLL, then add this // at the end of DLL. if (inDLL[x] == NULL) { appendNode(&head, &tail, stream[i]); inDLL[x] = tail; } else // Otherwise remove this character from DLL { removeNode(&head, &tail, inDLL[x]); inDLL[x] = NULL; repeated[x] = true; // Also mark it as repeated } } // Print the current first non-repeating character // from stream if (head != NULL) cout << "First non-repeating character so far " "is " << head->a << endl; } } /* Driver code */ int main() { findFirstNonRepeating(); return 0; }
This the code to find the firstnonrepeating character
M
#include<iostream> #include<stdlib.h> #include<ctype.h> #include<string.h> #define SIZE 50 using namespace std; struct STACK { char a [SIZE]; int top; }; typedef stuct STACK stack; void initialize (stack*s); void push (stack*s,char token); char pop (stack*s); int priority (char token); void intopost (stack*s,char infix[]); int main { char infix [SIZE]; stack s; system("CLS"); cout<<"\n\n Enter infix expression:"; cin>>infix; intopost(&s,infix); return 0; } void initialize(stack*s) { s->top= -1; } void push(stack*s,char token) { if(s->top!=SIZE-1) { s->top++; s->a[s->top]=token; } } char pop (stack*s) { char token; if(s->top!=-1) { token=s->a[s->top]; s->top--; return token; } return 0; } { int pri; switch(token) { case'^': pri=3; break; case'*': case'/': case'%': pri=2 break; case'+': case'-': pri=1; break; pri=0; default: } return pri; } { char postfix[SIZE],token; int i=0; j=0; length=0; initialize(s); push(s,'#'); length=strlen(infix); for(i=0; i<length; i++) { if(token=='(') { push(s,token); } else if (isalnum(token)) { postfix[j]=token; j++; } else if (token==')') { while(s->a[s->top]!='(') { postfix[j]=token; j++; } s->top--; } else { while(priority(s->a[s->top])>= priority(token)) { postfix[j]=pop(s); j++; } push(s,token); } while((token=pop(s))!='#') { postfix[j]= token; j++; } postfix[j]='10'; cout<<"\n\n The postfix Expression is"<<postfix; }
Hello guys please solve the bugs 👆
klimi
Implement linked list using object oriented programming language
oh the s made me think that you meant something else
Stay Forward
/getcbook
Tushar
Sry😂
Anonymous
Guys where can I get practice for beginners in the C language.
David
Write a program in C to get input time in second and convert it into Hours, minute and second..
1 #include<stdio.h> 2   3 void timeConversion(int seconds){ 4 double hours, minutes; 5   6 hours = seconds / 3600.0; 7 minutes = seconds / 60.0; 8   9 printf("%ds is %.5lfhr and %.5lfmin", seconds, hours, minutes); 10 } 11   12 int main(){ 13   14 int seconds; 15 printf("Enter the time in Seconds:"); 16 scanf("%d", &seconds); 17   18 timeConversion(seconds); 19 }
Anonymous
and perhaps use float instead which is enough, but double is also fine
David
I would make 3600.0 and 60.0 a const
Yes I can But it’s not too necessary when I can just write it😅😅
David
Well in this case
Anonymous
Also, I think the code is illogical
Anonymous
He needs how many hours and minutes the seconds are
Anonymous
If I input 3600 to your code, it won't output 1 hour, it will output 1 hour and 60 minutes
David
If I input 3600 to your code, it won't output 1 hour, it will output 1 hour and 60 minutes
U have to copy and paste the code into your IDE and check it don’t just analyze and come into conclusion
David
I debuged before sending it her It’s free from logical errors lol
David
Enter the time in Seconds:3600 3600s is 1.00000hr and 60.00000min It would print exactly this on ur shell
Anonymous
Because it should output 1hour and 0 minutes
Anonymous
1 hour and 60 minutes is 2 hours lol
David
He said convert minutes to hours and minutes 3600 minutes is 1hr and also 60 minutes
David
That was what I intended
David
Unless he means 3600s is 1hr and 0minute, I can re-write it
Anonymous
I think it needs to calculate the whole time to a hh:mm:ss format
Anonymous
So it would need to be 01:00:00 and not 01:60:00 lol
Anonymous
I think they want without a shortcut
Anonymous
It's very easy to calculate by yourself
Anonymous
Also time.h is not a library, just a header
David
It be like that when u do python too
Anonymous
ig
David
Yh
Nameful
What does =a mean in the context of the asm macro in GCC C?
Nameful
Like here: https://paste.centos.org/view/c89ac407 — what does =a mean?
J
What does =a mean in the context of the asm macro in GCC C?
iirc, GCC uses AT&T syntax. Which means, source = destination. Eg: 5 = a instead of a := 5 like in x86 or RISC or newer asm languages
Nameful
It's a constraint I think?
Anonymous
What does =a mean in the context of the asm macro in GCC C?
It means that the output variable retval is to be stored in the eax or rax register. The 'a' here refers to the specific register. If you specify =r instead of =a then the compiler will choose a suitable register.
Nameful
I see, thanks!
Mm
For what we use the % in c++ ?
Mm
And what it’s mean ?
Anonymous
Modulo
Mm
Example ?
Mm
Short example
Anonymous
#include <iostream> #include <time.h> #include <stdlib.h> using namespace std; int main() { int kullanici, rasgele; cout << "Lutfen Tahmininizi Giriniz(1-6) -> "; cin >> kullanici; cout << endl; if (kullanici <= 10 && kullanici >= 1) { srand(time(NULL)); rasgele = rand() % 6 + 1; } if (rasgele == kullanici) { cout << "Tahmininiz Dogru!" << endl; } else { cout << "Tahmininiz Yalnıs!"; cout << "Aslında Sonuc ->" << rasgele << endl; } else { cout << "Lutfen Verilen Araliklarda Giriniz" << endl; } }
Anonymous
hi i cant understand where i did wrong in this code but it not working can anybody help?
Anonymous
this*
Nameful
Bruh, what's the expected behaviour and what are you getting?
Nameful
Is there an error?
Anonymous
yes
Nameful
Then
Nameful
please show us the error so we can inspect it
Anonymous
please show us the error so we can inspect it
'{': no matching token was found
Nameful
'{': no matching token was found
Oh, I see. I think it might be because you have two else clauses on the last if statement
Nameful
That doesn't really make sense
Leovan
Ah, its if inside if
Anonymous
Nameful
Ohh
Nameful
Sorry, I didn't see with the messy indentation
David
1 #include<stdio.h> 2 #include<math.h> 3   4 void printVoltage(double t){ 5   6 // decleration and assignment of constants 7 const int BATTERYVOLTAGE = 100; 8 const int RESISTEANCE = 1000; 9 const double CAPACITANCE = 0.5; 10 double voltage; 11   12 // compute voltage across capacitor 13 voltage = BATTERYVOLTAGE * (1 - exp(-1)); 14   15 // display in tabular form 16 printf("Time(s) \t\t Voltage(v)"); 17 printf("\n%lf \t\t %lf ", t, voltage); 18   19 } 20 int main(){ 21     double t; 22     t = 0; 23     // call function printVoltage 24     printVoltage(t); 25     t += 0.5; 26     printVoltage(t); 27     t += 0.5; 28     printVoltage(t); 29     t += 0.5; 30 }