我编写了代码来转换时间的浮点值并将其转换为小时和分钟。如果输入 2.5 将返回 2:30(2 小时 30 分钟)。
$input = '2:5';
$num_hours=str_replace(":",".",$input,$num_hours) ;
$hours = floor($num_hours);
$mins = round(($num_hours - $hours) * 60);
echo $hour_one = $hours.'.'.$mins;
Run Code Online (Sandbox Code Playgroud)
但现在我想反转它:如果输入2:30它应该返回2.5.
我正在用C开发一个链表.我从txt文件中获取数据.但是当我尝试运行程序时,它给了我一个getc()的分段错误.这是代码,
#include<stdio.h>
#include<stdlib.h>
struct node{
char surname[100];
int number[1o0];
char name[100];
struct node *next;
};
typedef struct node Node;
int main()
{
FILE *ifp;
Node first ,*current;
//current =&first;
int i=0,j=0;
int ch;
char num[100],name[100];
ifp = fopen("tele.txt","r");
while (ch != EOF)
{
while(i<4)
{
ch = getc(ifp);
num[i++] = ch;
}
num[i] = '\0';
i=0;
while(ch !='\n')
{
ch = getc(ifp);
if(ch != '\t')
name[j++]=ch;
}
name[j] = '\0';
//ch = '\0';
printf("Number %s\nName %s\n ",num,name);
j=0;
}
fclose(ifp); …Run Code Online (Sandbox Code Playgroud) 如果我在运行时创建一个UIControl并将其添加到视图中(通过addSubview :),视图是否会释放它,或者我应该这样做?
这是一个示例代码:
-(IBAction) cloneMe: (id) sender{
if (!currentY) {
currentY = [sender frame].origin.y;
}
UIButton *clone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGRect cloneFrame = [sender frame];
cloneFrame.origin.y += currentY + cloneFrame.size.height + 30;
clone.frame = cloneFrame;
[clone setTitle:@"I'm a clone" forState:UIControlStateNormal];
[[sender superview] addSubview:clone];
currentY = cloneFrame.origin.y + cloneFrame.size.height;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Fedora CentOS 6.2,并且我意外地使用命令rm*删除了文件夹中包含的所有文件.所有文件都是文本文件,没有任何文件在其他任何地方打开过,或者有.swp文件.有什么方法可以让他们回来.提前致谢.
我有一个运行两个线程的ROS节点,它们都共享同一个类.该类具有两组参数"to read"和"to write"以在控制循环中更新.有两种情况会出现问题.
我的程序是一个节点,它将控制数据泵入四旋翼飞行器(情况1)并读取无人机数据以获得反馈(情况2).在这里,我可以控制线程A的执行频率,我知道线程B可以与其读/写外部源通信的频率.
线程A从控制源读取数据并更新"读取"参数.线程B不断读取这个"读取"参数并将它们写入无人机源.我的观点是,我不介意我是否错过了线程已读取的某些值,但是线程B可能会读取某些不是"真实"值的东西,因为线程A正在写入或类似的东西?
写入"读取"参数后的线程B读取将更新第二组"写入"的无人机状态.线程A再次需要读取这个"写入"参数并将它们写回控制源,就像我不关心是否遗漏了一个值因为我将获得下一个.
那么我需要一个互斥量吗?或者读取线程只会遗漏一些值但读取的内容将是正确且一致的?
BTW:我使用boost:threads来实现线程B作为线程A它是ROS节点本身.
假设我使用Python3.x有以下非常大的字符串,大小为几GB,长度为+10亿个字符:
string1 = "XYZYXZZXYZZXYZYXYXZYXZYXZYZYZXY.....YY"
Run Code Online (Sandbox Code Playgroud)
鉴于其长度,这已经需要+ GB加载到RAM中.
我想编写一个函数来替换每个Xwith A, Ywith B和Zwith C.我的目标是尽快做到这一点.当然,这也应该是有效的(例如,可能存在一些我不确定的RAM权衡).
对我来说最明显的解决方案是使用string模块和string.replace():
import string
def replace_characters(input_string):
new_string = input_string.replace("X", "A").replace("Y", "B").replace("Z", "C")
return new_string
foo = replace_characters(string1)
print(foo)
Run Code Online (Sandbox Code Playgroud)
哪个输出
'ABCBACCABCCABCBABACBACBACBCBCAB...BB'
Run Code Online (Sandbox Code Playgroud)
我担心这不是最有效的方法,因为我同时在如此大的数据结构上调用三个函数.
对于这么大的字符串,最有效的解决方案是什么?
我到处寻找问类似问题的人。这似乎不是:set fileformat=dos一个简单的or的情况:set fileformat=unix。
将文件写出并:set fileencoding=latin1进行:set fileformat=dos更改,以便git diff报告所有行都附加了 ^M。
该代码最初很高兴地存在为:
...
if (v == value32S)
{
...
Run Code Online (Sandbox Code Playgroud)
我做了极其彻底的改进(在 vim 的屏幕上看起来很好):
...
if (v == value32S ||
v == value33)
{
...
Run Code Online (Sandbox Code Playgroud)
但git diff要检查错误的更改显示:
diff --git a/csettings.cpp b/csettings.cpp 索引 1234..8901 100755 ---a/csettings.cpp +++ b/csettings.cpp @@ -2466,7 +2466,8 @@ bool MyClass::settingIsValid(QString s) #如果CONFIG_1 || 配置_2 - if (v == value32S) + if (v == value32S || ^M + v == …
我从下面的链接中获取代码来加密和解密文本但是在尝试运行此任何想法时我得到分段错误?
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static char b64revtb[256] = {
-3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*0-15*/
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16-31*/
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, /*32-47*/
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, …Run Code Online (Sandbox Code Playgroud) 下面的代码应该接受输入,然后存储它然后显示LED,将数字作为显示.然而,它提供随机LED,而不是正确的LED.我检查了一些事情,但我看不出有什么问题,你能帮忙吗?
#include <stdio.h>
int main( void )
{
/* Declare a data variable for each pixel. */
int a1, a2, a3, a4, a5 =0;
int b1, b2, b3, b4, b5 =0;
int c1, c2, c3, c4, c5 =0;
int d1, d2, d3, d4, d5 =0;
int e1, e2, e3, e4, e5 =0;
int f1, f2, f3, f4, f5 =0;
int g1, g2, g3, g4, g5 =0;
int h1, h2, h3, h4, h5 =0;
int i1, i2, i3, i4, i5 =0; …Run Code Online (Sandbox Code Playgroud)