It is a box containing coin coins. The tail is 17/20. Find the value of 'n'.
At McDonald's you can order and you can not order it at all?
It can be formed from the set.
Examples:
')
Input:
set [] = {'a', 'b'}, k = 3
Output:
a
b
aa
ab
ba
bb
aaa
aab
aba
abb
baa
bab
bba
bbb
Input:
set [] = {'a', 'b', 'c', 'd'}, k = 1
Output:
a
b
c
d
This is a singly linked list, delete the node. Note. Write a program to accomplish the task, pseudocode is accepted.
Write a C / C ++ code.
// C# program to print all // possible strings of length k using System; class GFG { // The method that prints all // possible strings of length k. // It is mainly a wrapper over // recursive function printAllKLengthRec() static void printAllKLength(char[] set, int k) { int n = set.Length; for (int j=0; j<=k; j++) { printAllKLengthRec(set, "", n, j); } } // The main recursive method // to print all possible // strings of length k static void printAllKLengthRec(char[] set, String prefix, int n, int k) { // Base case: k is 0, // print prefix if (k == 0) { Console.WriteLine(prefix); return; } // One by one add all characters // from set and recursively // call for k equals to k-1 for (int i = 0; i < n; ++i) { // Next character of input added String newPrefix = prefix + set[i]; // k is decreased, because // we have added a new character printAllKLengthRec(set, newPrefix, n, k - 1); } } // Driver Code static public void Main () { Console.WriteLine("First Test"); char[] set1 = {'a', 'b'}; int k = 3; printAllKLength(set1, k); Console.WriteLine("\nSecond Test"); char[] set2 = {'a', 'b', 'c', 'd'}; k = 1; printAllKLength(set2, k); } }
#include<stdio.h> #include<assert.h> #include<stdlib.h> /* Link list node */ struct Node { int data; struct Node* next; }; /* Given a reference (pointer to pointer) to the head of a list and an int, push a new node on the front of the list. */ void push(struct Node** head_ref, int new_data) { /* allocate node */ struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); /* put in the data */ new_node->data = new_data; /* link the old list off the new node */ new_node->next = (*head_ref); /* move the head to point to the new node */ (*head_ref) = new_node; } void printList(struct Node *head) { struct Node *temp = head; while(temp != NULL) { printf("%d ", temp->data); temp = temp->next; } } void deleteNode(struct Node *node_ptr) { struct Node *temp = node_ptr->next; node_ptr->data = temp->data; node_ptr->next = temp->next; free(temp); } /* Drier program to test above function*/ int main() { /* Start with the empty list */ struct Node* head = NULL; /* Use push() to construct below list 1->12->1->4->1 */ push(&head, 1); push(&head, 4); push(&head, 1); push(&head, 12); push(&head, 1); printf("Before deleting \n"); printList(head); /* I m deleting the head itself. You can check for more cases */ deleteNode(head); printf("\nAfter deleting \n"); printList(head); getchar(); return 0; }
// C++ program to remove comments from a C/C++ program #include <iostream> using namespace std; string removeComments(string prgm) { int n = prgm.length(); string res; // Flags to indicate that single line and multpile line comments // have started or not. bool s_cmt = false; bool m_cmt = false; // Traverse the given program for (int i=0; i<n; i++) { // If single line comment flag is on, then check for end of it if (s_cmt == true && prgm[i] == '\n') s_cmt = false; // If multiple line comment is on, then check for end of it else if (m_cmt == true && prgm[i] == '*' && prgm[i+1] == '/') m_cmt = false, i++; // If this character is in a comment, ignore it else if (s_cmt || m_cmt) continue; // Check for beginning of comments and set the approproate flags else if (prgm[i] == '/' && prgm[i+1] == '/') s_cmt = true, i++; else if (prgm[i] == '/' && prgm[i+1] == '*') m_cmt = true, i++; // If current character is a non-comment character, append it to res else res += prgm[i]; } return res; } // Driver program to test above functions int main() { string prgm = " /* Test program */ \n" " int main() \n" " { \n" " // variable declaration \n" " int a, b, c; \n" " /* This is a test \n" " multiline \n" " comment for \n" " testing */ \n" " a = b + c; \n" " } \n"; cout << "Given Program \n"; cout << prgm << endl; cout << " Modified Program "; cout << removeComments(prgm); return 0; }
Source: https://habr.com/ru/post/354684/
All Articles