SS
Someone good with c++ here?
Anonymous
Someone good with c++ here?
Just ask your question.
SS
Okay
Anonymous
Here my question
We wont do your homework for you. Tell us what you have done so far and the problem you are facing instead.
SS
Here my question
Lol just store them in a vector nd sort it
Anonymous
I as much i study , as much i loose
Anonymous
What concept?
initialization of arrays and more else
Sachin
ok
Артём
What is operator T& in std::reference_wrapper<T> ?? I can't figure it out, how to apply this operator (I don't want to use get()). source: https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper/get
Anonymous
What is operator T& in std::reference_wrapper<T> ?? I can't figure it out, how to apply this operator (I don't want to use get()). source: https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper/get
It is the same as get. It can be used to cast a reference_wrapper to T& or when you use a reference_wrapper where a T& is expected. It is just a conversion operator.
Артём
Thank you, I understood it means the other way to return the stored reference is to static_cast<T&>(my_refwraper) .
Anonymous
Thank you, I understood it means the other way to return the stored reference is to static_cast<T&>(my_refwraper) .
That is one way. The other way is for an implicit user defined conversion as I mentioned in my post above. Like for ex: void fun(int& obj){ } int main() { int a = 5; auto refi = std::ref(a); fun(refi); return 0; } Here the conversion is done implicitly for you by calling the "operator T&" method. If not for this method you would have to use fun(refi.get())
Anonymous
That is correct except for that there are no rows and columns actually in memory. Also s[i] is not a 2d array. It is just a plain array of 11 chars. These arrays may be allocated at random places in memory.
Anonymous
is am right?
s is a pointer to an array of char* pointers. Each individual char* pointer is a pointer to an array of 11 chars.
Anonymous
It is like this. It can be used like a 2D array but there are multiple indirections using pointers. Couldn't get hold of a piece of paper. So had to draw it on a tissue.
Sachin
thx you so much
Sachin
i got it now
Anonymous
English xd
Hanz
#ASK If i create an int variable, does it allocate bytes from the size of int? Or it will reallocate some memory only when i change the content so that more int value requires more memory? ex: int a = 0; int sa = sizeof a; a++; printf("%d", sizeof a == sa);
klimi
You are allocating on stack so that means it will just move the stack pointer and there you have your memory. In this case you will allocate 2x ints
Hanz
ooh alright! That make sense
Артём
Is second way less efficient? 1) void fill(vector<int>& v) { // fill v with large data } 2) vector<int> fill(vector<int>& v) { // fill c with large data return std::move(v); } ......... vector<int> v; 1) fill(v); 2) v = fill(v);
Anonymous
Is second way less efficient? 1) void fill(vector<int>& v) { // fill v with large data } 2) vector<int> fill(vector<int>& v) { // fill c with large data return std::move(v); } ......... vector<int> v; 1) fill(v); 2) v = fill(v);
The first method is the right way to do it. Btw since the 2nd method is also taking v by reference, why do you need to return anything? The way you have done it here will result in Undefined Behavior when you try to use v later because v's destructor will be called after the assignment. So the 2nd way is wrong.
@𝑺𝒐𝒃𝒌𝒂
Hi guys! I used the code below to have an idea of the largest and smallest values belonging to the integral data types. I'm working in windows 10, 64bt #include <iostream> #include <climits> using namespace std; int main() { cout<<"INTEGER: "<<endl; cout<<"Maximum: "<<INT_MAX<<endl; cout<<"Minimum: "<<INT_MIN<<endl; cout<<"LONG: "<<endl; cout<<"Maximum: "<<DBL_MAX<<endl; cout<<"Minimum: "<<DBL_MIN<<endl; cout<<"LONG LONG: "<<endl; cout<<"Maximum: "<<LLONG_MAX<<endl; cout<<"Minimum: "<<LLONG_MIN<<endl; return 0; } Output: INTEGER : Maximum: 2147483647 Minimum: - 2147483648 LONG: Maximum: 2147483647 Minimum: -2147483648 LONG LONG: Maximum: 9223372036854775807 Minimum: - 9223372036854775808
Anonymous
I noticed that INTEGER and LONG have the same values. I still confused, expecting to get different values (large in long output). Anybody can can help me. I will be thankful
The standard says that int should be atleast 2 bytes long, long should be atleast 4 bytes long and long long should be atleast 8 bytes. On most modern machines int and long are of the same size I.e. 4 bytes. And I am surprised that you are printing DBL_MAX for long but still getting LONG_MAX.
Anonymous
So using Long Long is safer than Long?
If you need big integers which need more than 4 bytes of storage, then yes you should use long long.
Hanz
If you need big integers which need more than 4 bytes of storage, then yes you should use long long.
so there is no 4 bytes number type for modern machine because long == int?
Hanz
int -> long -> long long
Golden Age Of
so there is no 4 bytes number type for modern machine because long == int?
int 4 bytes long int 4 bytes long long int 8 bytes
Anonymous
so there is no 4 bytes number type for modern machine because long == int?
long and int are both 4 bytes long on most x86 machines but it is not guaranteed to be so on all architectures. Whether you use int and long depends on how portable you want your code to be. If you need 4 byte integers and you use int and then try porting your code to a machine where int is just 2 bytes long, you will run into issues. In this case you should have used long.
Hanz
Thanks for the explanation guys 🙏 Because i use int for all my projects 😂 i will alter them
Anonymous
Now, I understand. For DBL_MAX, it was an error writing my message here. Sorry And thank you
In modern C++ code you should be using std::numeric_limits template class instead of using these macros defined in climits header.
RITESH
wap to demonstrate use of multi lavel inheritance.
RITESH
plese help me
Anonymous
Ok. How about cfloat? I mean, I was using it too for float types.
You can use std::numeric_limits for floating point types as well.
Anonymous
#ASK If i create an int variable, does it allocate bytes from the size of int? Or it will reallocate some memory only when i change the content so that more int value requires more memory? ex: int a = 0; int sa = sizeof a; a++; printf("%d", sizeof a == sa);
sizeof a is calculated at compile time. with enough optimisations this code will have no ints allocated at all. it will just print 1. https://godbolt.org/z/zda4KrjTG (even -O1 works)
@𝑺𝒐𝒃𝒌𝒂
Anonymous
I wish godbolt UI was more portable devices friendly. Their mobile interface sucks.
try moving the compiler/execution window to the bottom half
Anonymous
try moving the compiler/execution window to the bottom half
It brings up the keyboard whenever I click on the compiler window. I get so irritated that I simply close the browser tab. Switching between landscape and portrait mode screws it up even further.
Anonymous
Hello!
SS
You are given a roadmap of a country consisting of N cities and M roads. Each city has a traffic light. The traffic light has only 2 colors, Green and Red. All the traffic lights will switch their color from Green to Red and vice versa after every T seconds. You can cross a city only when the traffic light in the city is Green. Initially, all the traffic lights are Green. At a city, if the traffic light is Red, you have to wait for it to switch its color to Green. The time taken to travel through any road is C seconds. For each node x, find the number of routes that will take the minimum amount of time (in seconds) required to move from city 1 to city N passing through that city x. It is guaranteed that the given roadmap will be connected. Graph won’t contain multiple edges and self-loops. Input Format The first line contains 4 space-separated integers, N (1 <= N <= 103), M (N - 1 <= M <= (N(N-1)/2), T (1 <=T <=103) and C (1 <= C <=103). Next M lines contain two integers each, U and V denoting that there is a bidirectional road between U and V. Output Format Print N integers, where ith denotes the number of routes which will take the minimum amount of time (in seconds) required to move from city 1 to city N passing through that city i. Sample Testcase #0 Testcase Input 5 5 3 5 1 2 1 3 2 4 1 4 2 5 Testcase Output 1 1 0 1 1 Explanation Fastest path will be 1 - > 2 - > 5. You can reach city 2 in 5 seconds. After 3 seconds the traffic light in city 2 will turn Red. So in city 2, you have to wait for 1 second for the traffic light to turn Green. So total time will be 5 seconds (from city 1 to city 2) + 1 second (waiting time at city 2) + 5 seconds (from city 2 to city 5) = 11 seconds. There is no path from city 1 to city 5 through city 3
SS
#include<bits/stdc++.h> using namespace std; #define ll long long int vector<int> g[1001]; vector<pair<ll,vector<ll>>> pt; void dfs(ll st,ll e,ll vis[],vector<ll> rs,ll w){ rs.push_back(st); if(st == e){ pt.push_back({w*(rs.size()-1),rs}); return; } for(auto u : g[st]){ if(vis[u] == 0){ vis[st] = 1; dfs(u,e,vis,rs,w); vis[st] = 0; } } } int main() { ll n,m,t,c,u,v; cin>>n>>m>>t>>c; while(m--){ cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } vector<ll> rs; ll w = c; ll vis[n+1] = {0}; dfs(1,n,vis,rs,w); sort(pt.begin(),pt.end()); vector<ll> rt[n+1]; for(int i=0;i<pt.size();i++){ ll nes = pt[i].second.size(); for(auto u : pt[i].second){ rt[u].push_back(nes); } } ll trt[n+1] = {0}; trt[1] = 1; trt[n] = 1; for(int i=2;i<=n-1;i++){ if(rt[i].size() > 0){ ll tm = rt[i][0]; ll up = upper_bound(rt[i].begin(),rt[i].end(),tm) - rt[i].begin(); trt[i] = up; } } for(int i=1;i<=n;i++) cout<<trt[i]<<" "; return 0; }
SS
I tried this code but 7 test cases work Can someone pls resolve the issue?
tao
I recently used cppflow on VS 2019 on Windows 10. My original data is data in 4 columns per row. I want to use neural network to classify precipitation particles. I have trained and saved my model (.pb) on python. Because it is text data in .txt, and the example described in the cppflow document uses pictures as input, I would like to ask what is the function of cppflow input in .txt text?
tao
Thank you
Φ ☭
/rules
Anonymous
I recently used cppflow on VS 2019 on Windows 10. My original data is data in 4 columns per row. I want to use neural network to classify precipitation particles. I have trained and saved my model (.pb) on python. Because it is text data in .txt, and the example described in the cppflow document uses pictures as input, I would like to ask what is the function of cppflow input in .txt text?
?? Not sure I understand your question. The model file is the Pb file that you generated. It should be in a a folder by itself. Input is the tensor input you feed this model to get the output. If your model takes images as input then the input will be an image. If your model takes text data as input like to say determine the emotion of a person speaking that text then input will be text data. Not sure if this is what you are asking.
Shourya
Any wifi driver developers here? ..Need some help in debugging intel 7260 dual band driver..
Shourya
I know what debugging means ..Not asking to debug for me ..By help I meant if there are JTAG kind of debuggers available for intel drivers
Anonymous
hi
Jasur Fozilov 🐳
/get cbook
Jasur Fozilov 🐳
/get cppbookguide
Anonymous
1 || ++n > 5 Can someone explain to me why the ++n is not evaluated? I get that logical OR doesn't need to evaluate the second expression if the first expression is true, but prefix comes before logical OR in operator precedence, so why doesn't n get incremented? If this is how these two operators work, what's the point of placing prefix above logical OR in the same precedence table?
Anonymous
1 || ++n > 5 Can someone explain to me why the ++n is not evaluated? I get that logical OR doesn't need to evaluate the second expression if the first expression is true, but prefix comes before logical OR in operator precedence, so why doesn't n get incremented? If this is how these two operators work, what's the point of placing prefix above logical OR in the same precedence table?
You are confusing precedence, associativity and language rules. Yes it is true that ++ has a higher precedence than ||. It matters in an expression like ++n||<some expression>. Here precedence ensures that the expression is parsed as (++n)||<some expression> instead of ++(n||<some expression>. Associativity comes into picture when there are multiple operators with the same precedence in an expression. There is another thing called language rules which says that if the first operand of a logical or evaluates to true then the second operator should not be evaluated which is what happens in your case.
Alieya MIN
https://wandbox.org/permlink/fVrrnwoJjOuKd8tz hai guys i want to ask how to put the total quantity that have ordered per day and quantity that bought buy customer? any tips?
tao
here is my data sample
tao
/40.900352,0.406250,9.900000,0.380615,6.000000
Alieya MIN
Anonymous
https://pastebin.com/raw/nzSzJp67
I can see that you are displaying the total payment and also the individual quantities ordered. So what is the issue?
Anonymous
/40.900352,0.406250,9.900000,0.380615,6.000000
You can just create a tensor directly from this input. You dont even need a file. Look at their examples. They have lots of them covering different scenarios. Not all the inputs are image files.
Alieya MIN
its quite confusing there
Anonymous
its quite confusing there
Do you mean total number of all items sold?
Alieya MIN
Do you mean total number of all items sold?
yes.for each item how much they have been sold out