reverse

Python - Function to reverse strings in LIST

一笑奈何 提交于 2019-12-04 06:53:52
问题 studying Python as crazy and have many many questions. This time about function, i need to create 2 functions, first for numbers to sum up everything that user inputs in the list and second function, where user inputs some words in to the list and function without touching word indexes in the list, takes each word and returns reversed words (On the same index) I can show you my code, i think i don't have problems with numbers and its function, i need your help with reverse function, i tried

Does Stack<> constructor reverse the stack when being initialized from other one?

帅比萌擦擦* 提交于 2019-12-04 06:47:39
Here is the code: var s = new Stack<int>(); s.Push(1); s.Push(2); s.Push(3); s.Push(4); var ns = new Stack<int>(s); var nss = new Stack<int>(new Stack<int>(s)); and then let's see the result tbLog.Text += "s stack:"; while(s.Count > 0) { tbLog.Text += s.Pop() + ","; } tbLog.Text += Environment.NewLine; tbLog.Text += "ns stack:"; while (ns.Count > 0) { tbLog.Text += ns.Pop() + ","; } tbLog.Text += Environment.NewLine; tbLog.Text += "nss stack:"; while (nss.Count > 0) { tbLog.Text += nss.Pop() + ","; } produces the following output: s stack:4,3,2,1, ns stack:1,2,3,4, nss stack:4,3,2,1, So, ns

In-Place String Reverse in C

爱⌒轻易说出口 提交于 2019-12-04 06:31:04
问题 I am trying to learn the fundamentals of C, but I cannot figure out why this code doesn't work. The while loop in reverse() causes a bus error. I found almost identical code in a programming interview book as a valid solution, but neither this nor other similar methods I have seen posted here work for me without a bus error. #include <stdio.h> void reverse(char* str) { char* end = str; char tmp = 0; if(str) { while(*end) { end++; } --end; while(end>str) { tmp = *end; *end-- = *str; *str++ =

String reverse using pointers

和自甴很熟 提交于 2019-12-04 05:21:45
问题 I'm trying to reverse a string using pointers.When i try to print the reversed string instead of getting DCBA i'm getting out only as BA?Can anyone help me on this? #include<stdio.h> void reverse(char *); void main() { char str[5] = "ABCD"; reverse(str); } void reverse(char *str) { char *rev_str = str; char temp; while(*str) str++; --str; while(rev_str < str) { temp = *rev_str; *rev_str = *str; *str = temp; rev_str++; str--; } printf("reversed string is %s",str); } 回答1: You're losing your

C++ Printing a string in reverse using a for loop

你。 提交于 2019-12-04 05:14:27
问题 I have a program that prints out the characters of a string using a for-loop. It must also print the same characters in reverse, which is where I'm having problems. Can someone help me figure out why the second for-loop isn't executing? int main() { string myAnimal; cout << "Please enter the name of your favorite animal.\n"; cin >> myAnimal; // This loop works fine int i; for(i = 0; i < myAnimal.length(); i++){ cout << myAnimal.at(i) << endl; } // This one isn't executing for(i = myAnimal

recursive function digits of a positive decimal integer in reverse order c++

天涯浪子 提交于 2019-12-04 04:54:06
问题 I have an assignment to write a recursive function that writes the digits of a positive integer in reverse order. My problem is that the function doesn't display the reverse correctly. I know im supposed to use % or 10 when displaying the number and / of 10 when in the recursive call as well as the base case is supposed to be < 10. Here is my code. #include <iostream> using namespace std; int reverse(int,int); int main() { int number; int n; cout << " Enter number to reverse." << endl; cin >>

StrRev() Dosent Support UTF-8

旧巷老猫 提交于 2019-12-04 04:37:57
I'm trying to make a code that replace Arabic text to be supported in non Arabic supported programs in that i will be need to reverse the text after replace but its shows some garbage stuff instead of the wanted result Here Is The Code : <?php $string = "اهلا بك"; echo "$string <br>"; $Reversed = strrev($string); echo "<br><b>After Reverse</b><br><br>"; echo "<br> $Reversed"; ?> Result : اهلا بك After Reverse �٨� �؄ه٧ I need it to be the way it is but reversed ? not GARBAGE !! in order to make that strrev() support UTF-8 you need to use this Function function utf8_strrev($str){ preg_match_all(

Slice NSArray from end of array

点点圈 提交于 2019-12-04 04:26:43
What is the best way to "slice" an NSArray from the end, rather than the beginning, of the array (for example, finding the subarray containing the last few elements of a NSArray of unknown length)? In Python, you can use negative indices to accomplish this, e.g.: new_list = old_list[-5:-3] What's the most natural way to do this in Objective-C? There's nothing to match Python's nice syntax for this, but you could do: NSUInteger count = [myArray count]; NSArray * slice = [myArray subarrayWithRange:(NSRange){count-n, n}]; You could also write up a category for NSArray , something like: @interface

Flip non-zero values along each row of a lower triangular numpy array

与世无争的帅哥 提交于 2019-12-04 03:50:28
I have a lower triangular array, like B: B = np.array([[1,0,0,0],[.25,.75,0,0], [.1,.2,.7,0],[.2,.3,.4,.1]]) >>> B array([[ 1. , 0. , 0. , 0. ], [ 0.25, 0.75, 0. , 0. ], [ 0.1 , 0.2 , 0.7 , 0. ], [ 0.2 , 0.3 , 0.4 , 0.1 ]]) I want to flip it to look like: array([[ 1. , 0. , 0. , 0. ], [ 0.75, 0.25, 0. , 0. ], [ 0.7 , 0.2 , 0.1 , 0. ], [ 0.1 , 0.4 , 0.3 , 0.2 ]]) That is, I want to take all the positive values, and reverse within the positive values, leaving the trailing zeros in place. This is not what fliplr does: >>> np.fliplr(B) array([[ 0. , 0. , 0. , 1. ], [ 0. , 0. , 0.75, 0.25], [ 0. ,

reverse date javascript from yyyy/mm/dd to dd/mm/yyyy

丶灬走出姿态 提交于 2019-12-04 03:17:08
问题 I making an asp project and the date is displayed as yyyy/mm/dd but when the user press on the edit button for the form i need to replace the date format with dd/mm/yyyy this the asp code remember i need the user to show the date as yyyy/mm/dd in the table but when he pressing on a button i need the date to be reversed to dd/mm/yyyy <td class="hidden-phone">@EnnotaBAL.ArabicEncoding.GetArabicNumbers(transaction.PostDate.ToString("yyyy/MM/dd"))</td> and this the javascript code for the date