标签: reverse

C++:使用堆栈反转文本文件中的行

到目前为止我有这个代码:

#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main () {


ifstream in;
in.open("example.txt");

ofstream outfile;
outfile.open("out.txt");

stack<string> lines;
string temp;
while(getline(in, temp))
    lines.push(temp);
while(!lines.empty())
    outfile << lines.pop() << endl;

in.close();
outfile.close();

return 0;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,为什么我得到一个编译错误"在outfile中不匹配operator <<".

c++ stack reverse text lines

1
推荐指数
1
解决办法
1362
查看次数

在c中反转一个字符串

我试图扭转一个字符串到位.

void reverseStr(char *str)
{
 int i;
 int length;
 int last_pos;
 length = strlen(str);
 last_pos = length-1;

 for(i = 0; i < length / 2; i++)
 {
   char tmp = str[i];
   str[i] = str[last_pos - i];
   str[last_pos - i] = tmp;
 }
}

Program received signal SIGSEGV, Segmentation fault.
0x0000000000400893 in reverseStr (str=0x400974 "Haus") at main.c:102
102         str[i] = str[last_pos - i];
(gdb) print i
$1 = 0
(gdb) print last_pos
$2 = 3
(gdb) print str
$3 = 0x400974 …
Run Code Online (Sandbox Code Playgroud)

c string reverse

1
推荐指数
1
解决办法
4906
查看次数

以编程方式从左到右反向滚动 UIScrollView

我试图从左到右自动滚动,但我还没有成功。我正在评估以下表达式以改变方向(添加或减去像素)但是当滚动到达最终它被阻止...

(xContentSize - xOffset) >= CGRectGetWidth(_scroll.bounds)
Run Code Online (Sandbox Code Playgroud)

或者

(xContentSize - xOffset) > CGRectGetWidth(_scroll.bounds)
Run Code Online (Sandbox Code Playgroud)

任何的想法?

reverse uiscrollview right-to-left ios

1
推荐指数
1
解决办法
8565
查看次数

Django:在模板中找不到反向&gt; {% url %}

这个问题看起来很简单,并且在 SO 中多次描述,但我仍然无法弄清楚为什么它在我的情况下不起作用。

所以,我在urls.py 中声明了一个 url

urlpatterns = patterns('',
    url(r'^(?P<country>[-\w]+)/$', CountryListView.as_view(), name='list_by_country'),)
Run Code Online (Sandbox Code Playgroud)

在我的模板中,我正在调用 url

<a href="{% url 'list_by_country' country.country__name %}" >{{ country.country__name }}</a>
Run Code Online (Sandbox Code Playgroud)

但是,我收到无法反转 url的错误消息

Reverse for 'list_by_country' with arguments '(u'United Kingdom',)' and keyword arguments '{}' not found
Run Code Online (Sandbox Code Playgroud)

什么导致反向错误?参数中的空格可能不允许吗?


django url reverse arguments

1
推荐指数
1
解决办法
2007
查看次数

C中的字符串反转

我有用于反转字符串的代码.假设我键入'ABC',输出将为'CBA'.但是,有些代码行我完全不明白.

1    #include <stdio.h>
2    #include <string.h>
3
4    void print_reverse(char *s) {
5   size_t len = strlen(s);
6
7   char *t = s + len-1;
8   while(t >= s) {
9       printf("%c", *t);
10      t = t-1;
11  }
12  puts("");
13  }
14
15    int main()
16    {
17  char charinput[100];
18  printf("Enter character you want to reverse:");
19  fgets(charinput, 100, stdin);
20  print_reverse(charinput);
21  getchar();
22    }
Run Code Online (Sandbox Code Playgroud)

第7行和第8行有什么作用?指针t的输出是什么?

c string reverse

1
推荐指数
1
解决办法
334
查看次数

python中的reverse()用法?

sort() 和 reverse() 方法在排序或反转大列表时修改列表以节省空间。提醒您它们是通过副作用操作的,它们不会返回排序或反转的列表。

上面的文字可以在http://docs.python.org/2/library/stdtypes.html#mutable-sequence-types找到

“为空间经济修改清单”是什么意思?

例子:

x = ["happy", "sad"]
y = x.reverse()
Run Code Online (Sandbox Code Playgroud)

将返回None到y。那么为什么,

x.reverse()
Run Code Online (Sandbox Code Playgroud)

成功逆转x?

python reverse

1
推荐指数
1
解决办法
472
查看次数

如何在R中的数据框中重新编码一组变量

我有一个数据框,其中包含从1到5的不同变量.我想以5变为1的方式重新编码一些变量,反之亦然(x = 6-x).我想定义一个变量列表,这些变量将在我的数据帧中像这样重新编码.

这是我使用的方法lapply.我还没有真正了解它.

  #generate example-dataset
    var1<-sample(1:5,100,rep=TRUE)
    var2<-sample(1:5,100,rep=TRUE)
    var3<-sample(1:5,100,rep=TRUE)
    dat<-as.data.frame(cbind(var1,var2,var3))

    recode.list<-c("var1","var3")  
    recode.function<- function(x){          
    x=6-x
     }
    lapply(recode.list,recode.function,data=dat)
Run Code Online (Sandbox Code Playgroud)

reverse r lapply recode

1
推荐指数
1
解决办法
2239
查看次数

Haskell扭转尾巴但留下第一个元素

我在进行以下练习时遇到问题:

我应该反转列表中的所有元素,除了第一个元素,列表的第一个元素必须保持在原始位置.

正确的例子:

input: rvrsTail [1,2,3,4,5]
output [1,5,4,3,2]
Run Code Online (Sandbox Code Playgroud)

到目前为止我做了什么:

rvrsTail :: [x] -> [x]
rvrsTail xs = reverse ( tail xs)
Run Code Online (Sandbox Code Playgroud)

这确实反转了列表的尾部,但删除了第一个元素,因为我无法将第一个元素存储在变量中,所以我似乎无法理解如何解决这个问题.

错误输出:

input: rvrsTail [1,2,3,4,5]
output [5,4,3,2]
Run Code Online (Sandbox Code Playgroud)

由于这应该是初学者的练习,解决方案应该很简单.

reverse haskell list

1
推荐指数
1
解决办法
351
查看次数

打印多个没有空格的对象

我正在编写一个基本程序来反转任何4位数字.

我知道我采取的是一种非常复杂的方法,但这正是我教授所要求的.到目前为止我有:

print("This program will display any 4-digit integer in reverse order")

userNum = eval(input("Enter any 4-digit integer: "))

num1 = userNum % 10

userNum2 = userNum // 10

num2 = userNum2 % 10

userNum3 = userNum // 100

num3 = userNum3 % 10

userNum4 = userNum // 1000

num4 = userNum4 % 10

print(num1,num2,num3,num4)
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是print语句的输出给了我

x x x x
Run Code Online (Sandbox Code Playgroud)

当我愿意的时候

xxxx
Run Code Online (Sandbox Code Playgroud)

有什么建议?

python printing reverse spaces

1
推荐指数
1
解决办法
480
查看次数

生成并切片反转列表

这可能是愚蠢和基本的,但我如何获得列表 edcba

当我尝试:

import string
letters = string.ascii_lowercase
letters[4:0:-1]
Run Code Online (Sandbox Code Playgroud)

'EDCB'

这是有道理的,因为索引是[4,3,2,1].但是,使用-1以下结果:

letters[4:-1:-1]
Run Code Online (Sandbox Code Playgroud)

""

我知道我可以做"".join(reversed(letters[:5]))或使用列表理解,但我很好奇如何用消极的步骤做到这一点.

python reverse list

1
推荐指数
1
解决办法
59
查看次数

标签 统计

reverse ×10

python ×3

c ×2

list ×2

string ×2

arguments ×1

c++ ×1

django ×1

haskell ×1

ios ×1

lapply ×1

lines ×1

printing ×1

r ×1

recode ×1

right-to-left ×1

spaces ×1

stack ×1

text ×1

uiscrollview ×1

url ×1