Vova
Hi there. Does anyone sometimes not know how to normally output ascii characters from a file(txt) to the console in VS 2019 ?
Anonymous
Vova
Kosa
\Device\NUL
Hanz
Anonymous
Which gcc version is this ? I got Compile Error
This is a GCC extension and not standard compliant. The C99 Standard which introduced designated initializers allows only one ICE (Integer Constant Expression) in the index and not a range which is a GCC extension. The reason why you are getting a compiler error is probably because you are compiling using strict flags which disables these extensions.
https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
Vova
Anonymous
He specifically mentioned in the question that the stack must be implemented using an array which rules out using stack adaptor
Anonymous
神 ꜰʟᴀꜰꜰʏ
I already did, thanks
Anonymous
can I solve this problem?
Well you could by removing all the non printable characters from the file before processing it.
Or you could check if a character is printable by using the isprint function in ctype header before printing it
\Device\NUL
.
hi guys
.
Hi guys. can anyone help me to get the answer "Exactly! Good job."
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
static int64_t the_rolling_stones[] = { 94481, 91226, 95774, 30622, 75165, 72293 };
const static int N = sizeof(the_rolling_stones)/sizeof(*the_rolling_stones);
static void fail(){
puts("Nope!");
exit(EXIT_FAILURE);
}
static void aerosmith(int64_t e, int64_t o, int64_t u){
if ( e - u / 7 + 3 * o / 11 )
fail();
}
static void green_day(int n, int64_t v){
if (n<N) {
if ((n % 2) == 0)
green_day(++n, v);
else green_day(n + 1, v + the_rolling_stones[n]);
} else if (v != 213806)
fail();
}
static void anthrax(int b, int64_t x){
int64_t k = x;
for(; b<N; ++b) {
if (b % 2)
continue;
k *= the_rolling_stones[b];
}
if (k != 849419606)
fail();
}
int main(){
int64_t y, f, c;
printf("Please enter the right three numbers: ");
fflush(stdout);
if (scanf("%" SCNd64 " %" SCNd64 " %" SCNd64, &y,&f, &c) != 3)
fail();
the_rolling_stones[0] = y;
the_rolling_stones[5] = f;
the_rolling_stones[4] = c;
green_day(0, 90385);
anthrax(1, 7);
aerosmith(y, f, c);
puts("Exactly! Good job.");
}
.
I have to insert numbers to the input field on the console
.
I know, that's a stupid question. but I really need it. if you don’t have time, you can also wonder what to do by voice pls
itsmanjeet
Hey all,
Do we have any way to read struct value as bytes array by doing things like some bitshift or other
Means suppose i mapped a struct into buffer and i know its everything about its elements, count, data type order
As per my research struct is stored as a continuous memory block but the alignment is compiler dependent i.e. it change the order, add some bytes between the adjacent values
I want to read it like if i have a struct of int and char in byte array like
00 00 00 50, 02
i.e. first 4 bytes as int and next one bytes is char
attribute packed is not the option as input struct is not in my hand
Anshul
que:https://leetcode.com/problems/longest-increasing-path-in-a-matrix/
Approach1: https://pastebin.com/hbwfMBV1
Approach2: https://pastebin.com/fzFGdYM3
Here Approach1(that i saw in discuss section) works but approach 2 does not work, gives TLE. can anyone explain why? Both the approaches are exactly same
Ольга
Hi to all. I'm stuck and I can't figure out how I can get what I need. I need to find all n elements, they are thus x1 = 1, x2 = 2, x3 = 3 x4 = x1 + x2 + x3, x5 = x4 + x3 + x2, x6 = x5 + x6 + x4, ie from the previous three the following turns out. I solved the problem correctly, but I don't understand how to implement it with code. I hope for help
Ольга
Ольга
Because I really don't know
Anonymous
Hey, I'm making a simple program so my employees when they star working on a company they type his name and it gets print to a documento, my question is after theyre input I wanna start a stopwatch and when they introduce another company I wanna stop the stopwatch and store the time value, any ideas, I was using crime now but doesn't allow me to add or subtract other values
Anonymous
calculate the sum of numbers that will be divided by 100 to 3 and will have 5 remainders when divided by 3.
please help me with block scheme🥺
Ramil
Ramil
basically array[i + 3] = array[i + 2] + array[i + 1] + array[i]; is your loop body
Ramil
create simple for(int i = 0; i < size; ++i) loop and put that inside it
Ramil
you are done
Ольга
you are done
Thank you, I have another question it can be recursively function ?
Unashamed
If you have Seminar sample plaease
yahoo
how to i conpile confred.h confread.c main.c with gcc?
Ольга
Ramil
Ramil
I wnated to know what people think about VLAs. How dangerous are they? If they are, why does cpp has has vectors? Am I just overthinking?
Ramil
*wanted
\Device\NUL
\Device\NUL
They use heap
\Device\NUL
VLA is bad because it can cause stack overflow, and IT'S VERY SLOW
\Device\NUL
VLA is available on C99 And Above (optional) but not in ISO C++
Ramil
I thought is was on heap and that is why I was confused. Should have used my reading glasses.
Ramil
so what does C has for var lenght arrays?
\Device\NUL
https://t.me/programminginc/423156
Ramil
Ramil
do I just malloc()?
...
Qasem
Hi
\Device\NUL
sorry, care to explain why exactly it would be slow?
https://www.reddit.com/r/cpp/comments/s4u3sn/comment/hswb5vq/?utm_source=share&utm_medium=web2x&context=3
https://www.reddit.com/r/cpp/comments/s4u3sn/comment/hswdzzz/?utm_source=share&utm_medium=web2x&context=3
Ramil
...
\Device\NUL
ʙonuke
Conditionals
Fill in the blanks to compare the variables and print "hello" to the screen:
int a = 13;
int b = 12;
____ (a > ____) {
printf("hello");
}
ʙonuke
kindly anyone help me solve this
▀▄▀▄▀▄ Sennq ▄▀▄▀▄▀
/get cbook
浩
Hello, my code can be compiled by gcc7.3 with c++17 flag and clang6.0 with c++17 flag, but when I try to compiled it by msvc19.31.31107.0 with /std:c++17, it reports error. Then I try to compile with /std:c++latest, it works. Is my code using non-standard feature of c++? msvc with /std:c++17 says the expression result is not constant. I had a constexpr variable as constexpr bool is_vector_not_map = std::is_same_v<PositionType, std::vector<Size>> || std::is_same_v<PositionType, std::vector<std::pair<Symmetry, Size>>>; where Symmetry, Size, PositionType are all typename. and msvc report the error above when I try to do this: if constexpr (is_vector_not_map) { ... } else { ... }.
浩
error code is C2131
Anonymous
Michel
Hi, I have this class (pastebin) and somewhere along the line Valgrind gives me:
==271538== Use of uninitialised value of size 8
...other stuff...
==271538== Uninitialised value was created by a heap allocation
==271538== at 0x48472F3: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==271538== by 0x11361B: Array<double>::Array(unsigned long) (array.hpp:15)
last one in line 12 of the code shared.
Anyone can tell me why? Doesn't new double[n] allocates and initializes?
\Device\NUL
Pavel
Pavel
Pavel
Also, a minor thing, but it's better to use nullptr instead of NULL in C++
Michel
Michel
I didn't know I could put 0 size, just put 1 because it was the smallest that is an array, I guess
Sandeep
some one plz find segmentation fault in this
yue
why not gdb
Ludovic 'Archivist'
// { Driver Code Starts
// Program to find the maximum profit job sequence from a given array
// of jobs with deadlines and profits
#include<bits/stdc++.h>
using namespace std;
// A structure to represent a job
struct Job
{
int id; // Job Id
int dead; // Deadline of job
int profit; // Profit if job is over before or on deadline
};
// } Driver Code Ends
/*
struct Job
{
int id; // Job Id
int dead; // Deadline of job
int profit; // Profit if job is over before or on deadline
};
*/
class Solution
{
public:
//Function to find the maximum profit and the number of jobs done.
vector<int> JobScheduling(Job arr[], int n)
{
// your code here
vector<vector<int>> m(n);
for(int i=0;i<n;i++)
{
if(m[arr[i].dead].size())
{
m[arr[i].dead][0]=max(m[arr[i].dead][0],arr[i].profit);
}
m[arr[i].dead].push_back(arr[i].profit);
}
int task=0;
int profit=0;
for(auto x: m)
{
if(x[0])
{
task+=1;
profit+=x[0];
}
}
return {task,profit};
}
};
// { Driver Code Starts.
// Driver program to test methods
int main()
{
int t;
//testcases
cin >> t;
while(t--){
int n;
//size of array
cin >> n;
Job arr[n];
//adding id, deadline, profit
for(int i = 0;i<n;i++){
int x, y, z;
cin >> x >> y >> z;
arr[i].id = x;
arr[i].dead = y;
arr[i].profit = z;
}
Solution ob;
//function call
vector<int> ans = ob.JobScheduling(arr, n);
cout<<ans[0]<<" "<<ans[1]<<endl;
}
return 0;
}
// } Driver Code Ends
I advise you to learn how to use the tools in your toolchain. It probably features a few debugging tools that will immediately answer your question. On Unix-like systems gdb, valgrind, lldb can provide you with good debugging information.
Alternatively, if you do not have a debugger, use std::vector::at instead of std::vector::operator[]
Sandeep
Anonymous
printf is a nice choice to gdb
Anonymous
Sometimes it works even better than breakpoints