Ch1-7: clear the row i and column j iff a[i][j]==0

in this problem, both monish001 and hawstein use O(n^2) solution which first tranverse the char** a to find the a[i][j]==0 and mark that row/col to be: TRUE.

Then the send loop make the TURE row/col to be all 0.

//https://github.com/monish001/CPP-Programs/blob/master/CTCI/1.7Zeros.cpp
//Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.
#include
   
   
    
    
#include
    
    
     
     
using namespace std;
void swap(char &a, char&b){
    std::swap(a,b);
//    cout<
     
     <<" and "<<<" swapped.\n";
}

void print(char** a, int m, int n){
    for(int i=0; i
       
       
         r, c; for(int i=0; i 
         
       
    
    
   
   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由于ChitGPT是一个文本生成模型,无法直接在TradingView上运行代码。但是,我可以为您解释这段代码的作用和如何重写它。 该代码是一个基于价格波动的交易策略,用于确定市场的高点和低点,并在这些点位上进行买卖操作。具体来说,它首先定义了HH1和LL1,分别代表当当前价格突破前两个价格的高点和低点时,前一个价格应该被视为市场的高点或低点。然后,它使用VALUEWHEN函数找到HH1和LL1的实际值,并基于当前价格和这些值计算K1。如果K1为1,则当前价格应该被视为市场的低点,需要进行买入操作;如果K1为-3,则当前价格应该被视为市场的高点,需要进行卖出操作。最后,它使用DRAWLINE和DRAWSL等函数将这些高点和低点可视化,并在这些点位上进行买卖操作。 要在TradingView上重写这段代码,您需要使用Pine Script语言,并将这些函数和变量转换为Pine Script函数和变量。以下是一个示例代码,可能需要根据您的具体需求进行调整: ```pine script //@version=4 study(title="High/Low Strategy", overlay=true) h1 = iff(high < high[1] and high[1] < high[2], high[2], 0) l1 = iff(low > low[1] and low[1] > low[2], low[2], 0) hh = valuewhen(h1 > 0, h1, 0) ll = valuewhen(l1 > 0, l1, 0) k1 = iff(close > hh, -3, iff(close < ll, 1, 0)) k2 = valuewhen(k1 <> 0, k1, 0) g = iff(k2 == 1, hh, ll) g1 = valuewhen(barstate.islast, g, 0) drawnumber(low > 0, g1, g1, 0, color.cyan) w1 = k2 w2 = open - close ht = iff(open > close, open, close) lt = iff(open < close, open, close) drawline(w1 == 1, high, w1 == 1, ht, color.cyan) drawline(w1 == 1, low, w1 == 1, lt, color.cyan) drawline(w1 == -3, high, w1 == -3, ht, color.red) drawline(w1 == -3, low, w1 == -3, lt, color.red) stickline(w1 > 0, open, close, color.cyan, 1) stickline(w1 <= 0, open, close, color.red, 1) stickline(w2 > 0 and w1 <= 0, open, close, color.red, 0) stickline(w2 > 0 and w1 > 0, open, close, color.cyan, 0) drawline(w1 == 1 and w1[1] == 1, g, w1 == 1 and w1[1] == 1, g[1], color.green) drawline(w1 == -3 and w1[1] == -3, g, w1 == -3 and w1[1] == -3, g[1], color.yellow) drawsl(k2 == 1, g, 0, 1, 0, color.green) drawsl(k2 == -3, g, 0, 1, 0, color.yellow) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值