import Data.Char
x1 xs = sum(map (hilfsfunction) xs)
hilfsfunction x
| (ord 'x' > 97 && ord 'x' < 107) = (ord 'x' - 96)
| (ord 'x' > 48 && ord 'x' < 58) = (ord 'x' - 48)
| otherwise = 0
Run Code Online (Sandbox Code Playgroud)
我需要编写一个程序,其中函数接受一个字符串,然后使用它进行以下操作:
- 如果字母是a,将其更改为1
- 如果字母是其他内容,我应该使用相同的数字.
- 所有其他符号应更改为0
我现在的问题是,无论第一个案例或第二个案例是否属实,每次启动此程序时,总和为0.
示例:让我们取"6":
*Main Data.Char> ord '6' > 48 && ord '6' < 58
True
Run Code Online (Sandbox Code Playgroud)
在这之后:
*Main Data.Char> ord '6' - 48
6
Run Code Online (Sandbox Code Playgroud)
但如果我接受我的功能,每次都是这样的话......:
*Main Data.Char> x1 "6"
[0]
Run Code Online (Sandbox Code Playgroud)
我不知道我的错误在哪里.
是否有哈斯克尔这有助于我把一个元组的列表,例如任何函数或方法[(1,2),(3,4),(5,6)],并
返回[1,2,3,4,5,6]与列表理解的作品?
我专门搜索一个函数,它接受一个参数xs并且
在函数体(函数体)中有一个列表理解.
我目前正在使用 qt 为大学课堂编写一个版本的旅行商问题。为了将城市放置在 QGraphicsView 小部件上,我创建了这个程序,就像在这个 YouTube 教程中一样:https : //www.youtube.com/watch?v=hgDd2QspuDg
可悲的是,我只是像在教程中那样做每件事,但只有我得到了我的类是抽象类的错误,我不明白,因为我在这个类中的所有内容都是我在代码中定义的,并且我的类中没有任何未引用的内容。
对话框.h:
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QtCore>
#include <QtGui>
#include <QMessageBox>
#include <iostream>
#include <QPointF>
#include "mycity.h"
namespace Ui {
class Dialog;
}
class Dialog : public QDialog
{
Q_OBJECT
public:
explicit Dialog(QWidget *parent = nullptr);
~Dialog();
private slots:
double on_Kelvin_box_valueChanged();
double on_Iter_box_valueChanged();
double on_Radius_box_valueChanged();
double on_CVRatio_box_valueChanged();
void on_resetButton_clicked();
void on_startButton_released();
void on_stopButton_released();
private:
Ui::Dialog *ui;
QGraphicsScene *scene;
MyCity *city;
protected:
};
#endif // DIALOG_H
Run Code Online (Sandbox Code Playgroud)
mycity.h:
#ifndef …Run Code Online (Sandbox Code Playgroud)