David
But it’s having a logical error
artemetra 🇺🇦
David
Thanks
Ultraman
/rules
j. c o l e
What's up guys
j. c o l e
i need help for one homework
j. c o l e
j. c o l e
To attract buyers, manager Vasya laid out N products on a long shelf in a row from the beginning of the shelf The i-th product has the code Ai where a i is an integer number of the corresponding product in the catalog. Vasya came up with a theory that if there are three identical products nearby, then buyers lose interest and go to another store. Help him choose the longest section of the shelf. which does not contain three goods of the same type in a row. the first line contains an integer n(one greater than N, greater than 200000) the number of goods on the shelf the second line contains N integers Ai (1>ai>10^9) denoting the product code. the same goods are denoted by the same codes different - different result format Print the number of the last product on the longest section you are looking for goods are nominated from 1 to N if there are several longest sections Print the first of them.
j. c o l e
this is my homework.
alice
if the user enters a blank please say "nothing entered". how can i do this?
J
I think an if statement will do the trick.(Assuming you are getting a line(including white spaces))
Kaashᅠ
anyone plz define constructor and its work in C++?
J
anyone plz define constructor and its work in C++?
(Assuming you already searched google on it)
Constructor is a special type of member function for initialising values.
class X{
private:
int i; // Values are not initialised here
X(){ //This is a default constructor and wont take any values
i = 0; // i is initialised with value 0
}
};
int main() {
X x; // X() in class X is called here and i is initialised with value 0
}
shriman_deepak
ᴹᵒʰᵃᵐᵐᵃᵈ
./fanmod 3 100 1 inputFile 1 0 0 2 0 0 0 10 3 3 out_inputFile 1 0
bad dispatch vector
Did you forget to link naugraph.o?
Hello friends
This error appears to me. I asked if you said you did not compile it correctly, does anyone have a solution?
#!/bin/sh
echo --- CVS ---
cvs update -d
echo --- NAUTY ---
cd nauty
rm *.o
gcc -c -O3 *.c
cd ..
echo --- COMPILE ---
rm *.o
g++ -c graph64.cpp
g++ -c output.cpp
g++ -c random.cpp
g++ -c maingraph.cpp
g++ -c main.cpp
echo --- LINK ---
g++ -o fanmod graph64.o output.o random.o maingraph.o main.o nauty/gtools.o nauty/nautil.o nauty/nauty.o nauty/nautinv.o nauty/naugraph.o
strip fanmod
#echo --- ZIP ---
#rm fanmod-linux-gtk-i386.zip
#zip fanmod-linux-gtk-i386.zip fanmod
#scp fanmod-linux-gtk-i386.zip login.minet.uni-jena.de:fanmod-linux-gtk-i386.zip
klimi
ᴹᵒʰᵃᵐᵐᵃᵈ
klimi
oh sure... i thought that it's the source
ברני
Hey sorry if its irrelevant, but can someone send me a same group like this for Python?🥺
klimi
Nameful
@python
That's a lot of members
klimi
GIDDY
Vb programmer?
?
why it's really required to explicitly state the return type of a function in C/C++ during it's definition ? why can't the compiler(of course it can) figure that out or why both the C and C++ standards don't let the compiler implementers to let the compiler figure that out with the help of the literal appearing after "return" in a return statement ?? if anyone can explain this to me and point to good authoritative resources discussing about it and point me to the relevant section/s where the rationale behind this decision is explained fully in both the C and C++ standards it will be very great. i almost read about "type specifiers", "function definitions" and googled hoping that it will shade some light to my question but i didn't find any useful information about it.
Cristina
guys can you help me? Im an first year I.T student
Cristina
how can I make a program with 5 subprograms?
Cristina
Shahrukh
/* sum of all subarray using reverse lookup
in 1d array
*/
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int ar[n];
for(int i=0; i<n;i++)
{
cin>>ar[i];
}
int sum =0;
for(int i=0; i<n;i++)
{
sum+=(i+1)*(n-i)*ar[i];
}
cout<<sum<<endl;
return 0;
}
Shahrukh
How to handle integer overflow situation
Anonymous
Shahrukh
If if I use long long then also overflow happen for large value
Leovan
J
Ravi
how can I make a program with 5 subprograms?
by definations, if I say the subprogram is the part of code which can be reused any number of times., in c or C++ we have nothing but the functions which does the same. So simply you should write 5 different functions for achieving the goal,
r3tr0m
What's up
Akim
Good afternoon! I need to open a file in C using unicode_escape encoding. Could one please tell me, how can I achieve this?
Leovan
Why in buff after this function garbage in the last symbols (as when accessing an uninitialized variable)?
char * read_from_file(const char * path)
{
std::ifstream fin(path);
if (fin)
{
fin.seekg(0, fin.end);
size_t length = fin.tellg();
fin.seekg(0, fin.beg);
char * buff = new char[length];
fin.read(buff, length);
fin.close();
return buff;
}
return nullptr;
}
Anonymous
#include <iostream>
using namespace std;
class const1;
class const2
{
float a1, a2;
friend void enterValue(const1, const2);
public:
friend void print(const1, const2);
};
class const1
{
float a, b;
public:
friend void enterValue(const1, const2);
friend void print(const1, const2);
};
void enterValue(const1 c1, const2 c2)
{
cout << " enter value of a ";
cin >> c1.a;
cout << " entet the value of b ";
cin >> c1.b;
cout << endl;
cout << "entet tha value of a1 ";
cin >> c2.a1;
cout << "enter the value of a2 ";
cin >> c2.a2;
cout << endl
<< endl;
}
void print(const1 c1, const2 c2)
{
cout << " the value of x is :" << c1.a << endl;
cout << " the value of y is " << c1.b << endl;
cout << " the value of a1 and x is :" << c2.a1 << endl;
cout << " the value of a2 and x is :" << c2.a2 << endl;
}
int main()
{
const1 s1;
const2 s2;
enterValue(s1, s2);
print(s1, s2);
cout << endl
<< " hello Peter";
}
Anonymous
why s1 and s2 is printing garbage value ??🥲
artemetra 🇺🇦
why s1 and s2 is printing garbage value ??🥲
there's a bunch of things to unpack
first, when you declare a variable like you do with s1 and s2, you are not initializing it. what is happening is that it's allocating some range in memory by your OS, but that range is not cleared , which means that whatever was there before assigning those variables gets reinterpreted as types of those new variables.
TL;DR: initialize s1 and s2 with some values
artemetra 🇺🇦
why s1 and s2 is printing garbage value ??🥲
the second thing is that when you call the function enterValue, both s1 and s2 get passed by copying the value. this means that all that happens inside that function with those variables is discarded after you leave its scope. use references or pointers
artemetra 🇺🇦
#include <iostream>
using namespace std;
class const1;
class const2
{
float a1, a2;
friend void enterValue(const1, const2);
public:
friend void print(const1, const2);
};
class const1
{
float a, b;
public:
friend void enterValue(const1, const2);
friend void print(const1, const2);
};
void enterValue(const1 c1, const2 c2)
{
cout << " enter value of a ";
cin >> c1.a;
cout << " entet the value of b ";
cin >> c1.b;
cout << endl;
cout << "entet tha value of a1 ";
cin >> c2.a1;
cout << "enter the value of a2 ";
cin >> c2.a2;
cout << endl
<< endl;
}
void print(const1 c1, const2 c2)
{
cout << " the value of x is :" << c1.a << endl;
cout << " the value of y is " << c1.b << endl;
cout << " the value of a1 and x is :" << c2.a1 << endl;
cout << " the value of a2 and x is :" << c2.a2 << endl;
}
int main()
{
const1 s1;
const2 s2;
enterValue(s1, s2);
print(s1, s2);
cout << endl
<< " hello Peter";
}
void enterValue(const1* c1, const2* c2)
{
cout << " enter value of a ";
cin >> c1->a;
cout << " entet the value of b ";
cin >> c1->b;
cout << endl;
cout << "enter the value of a1 ";
cin >> c2->a1;
cout << "enter the value of a2 ";
cin >> c2->a2;
cout << endl << endl;
}
this will work, and use this: enterValue(&s1, &s2); to call the function
artemetra 🇺🇦
mito
void addone(int *n) {
(*n)++;
}
int main(){
int n;
printf("Before: %d\n", n);
addone(&n);
printf("After: %d\n", n);
}
Is this pass by reference or pass by value ?
artemetra 🇺🇦
mito
artemetra 🇺🇦
wdym ?
void addone(int n) // by value, won't work
{ n++; }
void addone(int& n) // by reference, will work
{ n++; }
void addone(int* n) // by pointer, will work
{ (*n)++; }
mito
artemetra 🇺🇦
mito
no
So then, what does pass by reference in C mean ?
Does it indicate passing the pointers as pass by reference?
Clash
#include <iostream>
#include<cmath>
using namespace std;
int dif(int a,int b){
int c=a-b;
return c;
}
int main() {
int t;
cin>>t;
while(t--){
int a,b,c,p,q,r,avg,w;
cin>>a>>b>>c>>p>>q>>r;
avg=(p+q+r)/2;
if(p==q&&p==r)
w=a<b&&a<c?w=p+b+c:b<c?a+q+c:a+b+r;
else if(p==q&&p>r){
if(dif(a,c)>dif(p,r)&&dif(b,c)>dif(p,r)){
if(a>b)
w=a+q+c;
else
w=p+b+c;}
}
else if(r==q&&r>p){
if(dif(c,a)>dif(q,p)&&dif(b,a)>dif(q,p)){
if(c>b)
w=a+q+c;
else
w=a+b+r;}
}
else if(p==r&&p>q){
if(dif(a,b)>dif(q,p)&&dif(c,b)>dif(q,p)){
if(a>c)
w=a+b+r;
else
w=p+b+c;}
}
else{
p>q&&p>r?w=p+b+c:q>r?w=a+q+c:w=a+b+c;
}
if(w>avg)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
guys how to make this code more efficient
Miss aggarwal
If I facing some difficulty in code , can i share pic of my laptop screen for code .??
Talula
R
can anyone tell the code for print bill in console visual studio c++
artemetra 🇺🇦
Anonymous
#include <iostream>
#include<cmath>
using namespace std;
int dif(int a,int b){
int c=a-b;
return c;
}
int main() {
int t;
cin>>t;
while(t--){
int a,b,c,p,q,r,avg,w;
cin>>a>>b>>c>>p>>q>>r;
avg=(p+q+r)/2;
if(p==q&&p==r)
w=a<b&&a<c?w=p+b+c:b<c?a+q+c:a+b+r;
else if(p==q&&p>r){
if(dif(a,c)>dif(p,r)&&dif(b,c)>dif(p,r)){
if(a>b)
w=a+q+c;
else
w=p+b+c;}
}
else if(r==q&&r>p){
if(dif(c,a)>dif(q,p)&&dif(b,a)>dif(q,p)){
if(c>b)
w=a+q+c;
else
w=a+b+r;}
}
else if(p==r&&p>q){
if(dif(a,b)>dif(q,p)&&dif(c,b)>dif(q,p)){
if(a>c)
w=a+b+r;
else
w=p+b+c;}
}
else{
p>q&&p>r?w=p+b+c:q>r?w=a+q+c:w=a+b+c;
}
if(w>avg)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
guys how to make this code more efficient
The diff function seems totally pointless
artemetra 🇺🇦
#include <iostream>
#include<cmath>
using namespace std;
int dif(int a,int b){
int c=a-b;
return c;
}
int main() {
int t;
cin>>t;
while(t--){
int a,b,c,p,q,r,avg,w;
cin>>a>>b>>c>>p>>q>>r;
avg=(p+q+r)/2;
if(p==q&&p==r)
w=a<b&&a<c?w=p+b+c:b<c?a+q+c:a+b+r;
else if(p==q&&p>r){
if(dif(a,c)>dif(p,r)&&dif(b,c)>dif(p,r)){
if(a>b)
w=a+q+c;
else
w=p+b+c;}
}
else if(r==q&&r>p){
if(dif(c,a)>dif(q,p)&&dif(b,a)>dif(q,p)){
if(c>b)
w=a+q+c;
else
w=a+b+r;}
}
else if(p==r&&p>q){
if(dif(a,b)>dif(q,p)&&dif(c,b)>dif(q,p)){
if(a>c)
w=a+b+r;
else
w=p+b+c;}
}
else{
p>q&&p>r?w=p+b+c:q>r?w=a+q+c:w=a+b+c;
}
if(w>avg)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
guys how to make this code more efficient
what is it even supposed to do? what are a,b,c,p,q,r and w?
Kartik
case '*' :
multiplyNum(num1, num2);
break;
case 'anythingElse' :
multiplyNum(num1, num2);
break;
I've made a calculator using switch statement. All operations i.e. +, -, /, %...are showing expected results but * is not showing anything.
I tried replacing * with other characters and it works. Why is this happening that * symbol is not calling the function?
Ps: i tried replacing case for addition(+) with * and now add function is not showing anything(function is not even being called actually)
Kartik
I'm using cmd line to run it.
I just tried : ./calc 16 \* 2
And i got the expected result.
'\*' working instead of just '*'. Why?
Hima
Kartik
https://pastebin.com/jK0cBzU9
Kartik
Case can be found at line 57
And the function at line 152
Kartik
Anonymous
Does anyone solve on codeforces?
Anonymous
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main() {
int kullanici, rasgele, puan = 10;
srand(time(0));
rasgele = rand() % 10 + 1;
cout << "Lutfen Gelen Sayiyi Tahmin Ediniz (10-1) -> ";
cin >> kullanici;
cout << endl;
if (kullanici <= 10 && kullanici >= 1) {
while (kullanici == rasgele) {
if (kullanici <= rasgele) {
cout << "Puaniniz Eksildi! Daha Buyuk Bir Sayi Giriniz -> ";
puan -= 10;
}
else if (kullanici >= rasgele) {
cout << "Puaniniz Eksildi! Daha Kucuk Bir Sayi Giriniz -> ";
puan -= 10;
}
else {
cout << "Tebrikler Dogru Bilginiz!";
cout << "Kalan Puaniniz -> " << puan << endl;
}
}
}
}
Anonymous
hi i writed this code but it isnt work
Anonymous
its cant printed on the screen
Anonymous
can anybody help?
Pavel
Anonymous
i made it
Sarah
Any one here use OpenGL ?
Sarah
I have error but thing it’s because the library not in my environment can any one run it to check please ?
Sarah
#ifdef APPLE
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include<math.h>
#include <stdlib.h>
void Draw() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glFlush();
}
void Initialize() {
glClearColor(255, 0.0, 25.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}
int main(int iArgc, char** cppArgv) {
glutInit(&iArgc, cppArgv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(650, 350);
glutInitWindowPosition(200, 200);
glutCreateWindow("first window");
Initialize();
glutDisplayFunc(Draw);
glutMainLoop();
return EXIT_SUCCESS;
}
Ravi
Sachin
how to print first 3 values of map in c++ ?