klimi
what's going on?
klimi
some exam in india?
klimi
Ah i see
klimi
which institute?
Sarathy
klimi
how to solve it?
Sarathy
It's just a fascinating number program
Plz do help for us
Anonymous
@Neko_cpp
klimi
Dima
noobs
Anonymous
Sri
C program for fascinating number
Dima
Asdew
I can't understand why they study CS/whatever they are studying if they don't even seem to intend on programming in the future.
Dima
retard
Anonymous
Anyone give me competitive programs to practice in c and c++
klimi
Anonymous
I've coded time analysis program in cpp, and I am getting this error, does anyone knows the reason.
Anonymous
free(): invalid next size(normal)
Aborted (core dumped)
Anonymous
I've searched on google and duckduck go, no reliable solution
Anonymous
#include<iostream>
#include<chrono>
#include<random>
#include<cstdlib>
#include<vector>
#include<fstream>
#include<stdint.h>
using namespace std;
using namespace std::chrono;
int found=0;
int notfound;
double ltimex = 0;
double lavgtime = 0;
double btimex = 0;
double bavgtime = 0;
int pos;
int partition(vector<int>a, int first, int last){ //partition algo for quick sort
int pivot = a[last];
int pi = a[first];
for(int i = first; i<=last-1; i++){
if(a[i]<pivot){
swap(a[i], a[pi]);
pi++;
}
swap(a[last], a[pi]);
}
return pi;
}
int quicksort(vector<int>a, int first, int last){ //function for quick sort
if(first<last){ //break statement for recursive call.
int pi=partition(a, first, last); //pi=partioning index
quicksort(a,first, pi-1);
quicksort(a, pi+1, last);
}
}
int linearsearch(vector<int> a, int key){ //linear search
int pos,j;
for(j=1; j<a.size(); j++){
if(key==a[j]){
pos = j;
found++;
break;
}
}
if(pos == j){
return pos;
}
else
{
notfound = -1;
return notfound;
}
}
int binarysearch(vector<int>a, int fst, int lst, int key){
int mid = fst+lst/2;
if(key==a[mid])
return mid;
if (key>a[mid]){
binarysearch(a,mid+1, lst, key);
}
binarysearch(a, fst, mid-1, key);
}
int main(){
int i,j,l;
srand(time(0));
for(i=5000; i<=50000; i=i+5000){
vector<int>a;
for(j=0; j<100; j++){ //loop for test case, 100
for(int k=1; k<=i-1; k++){
int z = rand()%i+100;
a.push_back(z);
}
int key = rand()%i+100;
//sorting of the array.
quicksort(a, 0, i); //quick sort function call
//time functions.
//linear search
auto start = high_resolution_clock::now();
linearsearch(a,key);
auto stop = high_resolution_clock::now();
ltimex = duration_cast<microseconds>(stop - start).count();
lavgtime = lavgtime + ltimex;
//binary search
auto bstart = high_resolution_clock::now();
binarysearch(a,0,i,key);
auto bstop = high_resolution_clock::now();
btimex = duration_cast<microseconds>(bstop - bstart).count();
bavgtime = bavgtime + btimex;
}
cout << "\nAverage Time taken by linear function: "<< lavgtime << " microseconds";
cout << "\nAverage Time taken by binary function: "<< bavgtime << " microseconds";
ofstream fout;
fout.open("data.csv", ios::out | ios::app);
while (fout)
{
if (pos != -1)
fout<<i<<","<<lavgtime<<","<<bavgtime<<"\n";
break;
}
fout.close();
}
return 0;
}
Anonymous
I've used free() nowhere in the program
klimi
Anonymous
klimi
long snippet of code.... but whatever idc much but other admins might
Anonymous
shoud I pastebin it?
Anonymous
#include<iostream>
#include<chrono>
#include<random>
#include<cstdlib>
#include<vector>
#include<fstream>
#include<stdint.h>
using namespace std;
using namespace std::chrono;
int found=0;
int notfound;
double ltimex = 0;
double lavgtime = 0;
double btimex = 0;
double bavgtime = 0;
int pos;
int partition(vector<int>a, int first, int last){ //partition algo for quick sort
int pivot = a[last];
int pi = a[first];
for(int i = first; i<=last-1; i++){
if(a[i]<pivot){
swap(a[i], a[pi]);
pi++;
}
swap(a[last], a[pi]);
}
return pi;
}
int quicksort(vector<int>a, int first, int last){ //function for quick sort
if(first<last){ //break statement for recursive call.
int pi=partition(a, first, last); //pi=partioning index
quicksort(a,first, pi-1);
quicksort(a, pi+1, last);
}
}
int linearsearch(vector<int> a, int key){ //linear search
int pos,j;
for(j=1; j<a.size(); j++){
if(key==a[j]){
pos = j;
found++;
break;
}
}
if(pos == j){
return pos;
}
else
{
notfound = -1;
return notfound;
}
}
int binarysearch(vector<int>a, int fst, int lst, int key){
int mid = fst+lst/2;
if(key==a[mid])
return mid;
if (key>a[mid]){
binarysearch(a,mid+1, lst, key);
}
binarysearch(a, fst, mid-1, key);
}
int main(){
int i,j,l;
srand(time(0));
for(i=5000; i<=50000; i=i+5000){
vector<int>a;
for(j=0; j<100; j++){ //loop for test case, 100
for(int k=1; k<=i-1; k++){
int z = rand()%i+100;
a.push_back(z);
}
int key = rand()%i+100;
//sorting of the array.
quicksort(a, 0, i); //quick sort function call
//time functions.
//linear search
auto start = high_resolution_clock::now();
linearsearch(a,key);
auto stop = high_resolution_clock::now();
ltimex = duration_cast<microseconds>(stop - start).count();
lavgtime = lavgtime + ltimex;
//binary search
auto bstart = high_resolution_clock::now();
binarysearch(a,0,i,key);
auto bstop = high_resolution_clock::now();
btimex = duration_cast<microseconds>(bstop - bstart).count();
bavgtime = bavgtime + btimex;
}
cout << "\nAverage Time taken by linear function: "<< lavgtime << " microseconds";
cout << "\nAverage Time taken by binary function: "<< bavgtime << " microseconds";
ofstream fout;
fout.open("data.csv", ios::out | ios::app);
while (fout)
{
if (pos != -1)
fout<<i<<","<<lavgtime<<","<<bavgtime<<"\n";
break;
}
fout.close();
}
return 0;
}
bad index usage
Anonymous
Anonymous
int pi = a[first];
...
swap(a[i], a[pi]);
Anonymous
oh okay thanks
Anonymous
now I am receiving "segmentation fault" 😂😅
I'll try fixing this on my own
Anonymous
thanks for the article
Anonymous
Anonymous
Anonymous
I know 😎
I'm a relatively high ranked coder in Google CodeJam, Code Forces, and Top Coders
klimi
Dima
courses are super worthless
Dima
won’t show you your real skill
klimi
hey dimka why is stdlib.h retarded
klimi
AND THIS IS WHY I HATE PROGRAMMING
Nameful
klimi
/nix/store/fj6rjsjnl08p57gh7dms3njgniiw3fxq-gcc-9.2.0/include/c++/9.2.0/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
75 | #include_next <stdlib.h>
klimi
whatever i try
klimi
oh another new error nice now they are 2
klimi
/nix/store/fj6rjsjnl08p57gh7dms3njgniiw3fxq-gcc-9.2.0/include/c++/9.2.0/cmath:45:15: fatal error: math.h: No such file or directory
45 | #include_next <math.h>
Nameful
Seems your installation is fucced
klimi
stdlib.h? yes xD
klimi
عزة
hello . can you answer this question? why 0!=1
klimi
cuz it is defined like that
klimi
عزة
عزة
ok and why any number Divided zero Equals Unknown for Ex
1÷0= Unknown??
Anonymous
klimi
Dima
lol
Anonymous
pastebin
Anonymous
can't use here
Anonymous
#include<iostream>
#include<chrono>
#include<random>
#include<cstdlib>
#include<vector>
#include<fstream>
#include<stdint.h>
using namespace std;
using namespace std::chrono;
int found=0;
int notfound;
double ltimex = 0;
double lavgtime = 0;
double btimex = 0;
double bavgtime = 0;
int pos;
int partition(vector<int>a, int first, int last){ //partition algo for quick sort
int pivot = a[last];
int pi = first;
for(int i = first; i<=last-1; i++){
if(a[i]<pivot){
swap(a[i], a[pi]);
pi++;
}
swap(a[last], a[pi]);
}
return pi;
}
int quicksort(vector<int>a, int first, int last){ //function for quick sort
if(first<last){ //break statement for recursive call.
int pi=partition(a, first, last); //pi=partioning index
quicksort(a,first, pi-1);
quicksort(a, pi+1, last);
}
}
int linearsearch(vector<int> a, int key){ //linear search
int pos,j;
for(j=1; j<a.size(); j++){
if(key==a[j]){
pos = j;
found++;
break;
}
}
if(pos == j){
return pos;
}
else
{
notfound = -1;
return notfound;
}
}
int binarysearch(vector<int>a, int key){
int fst = 0;
int lst = a.size()-1;
while (fst<=lst)
{
int mid = fst+lst/2;
if(a[mid]=key) return mid;
else if (a[mid]<key) fst=mid+1;
else lst = mid - 1;
}
return -1;
}
int main(){
int i,j,l;
srand(time(0));
for(i=500; i<=10000; i=i+5000){
vector<int>a;
for(j=0; j<100; j++){ //loop for test case, 100
for(int k=1; k<=i-1; k++){
int z = rand()%i+100;
a.push_back(z);
}
int key = rand()%i+100;
//sorting of the array.
quicksort(a, 0, i); //quick sort function call
//time functions.
//linear search
auto start = high_resolution_clock::now();
linearsearch(a,key);
auto stop = high_resolution_clock::now();
ltimex = duration_cast<microseconds>(stop - start).count();
lavgtime = lavgtime + ltimex;
// //binary search
auto bstart = high_resolution_clock::now();
binarysearch(a,key);
auto bstop = high_resolution_clock::now();
btimex = duration_cast<microseconds>(bstop - bstart).count();
bavgtime = bavgtime + btimex;
}
cout << "\nAverage Time taken by linear function: "<< lavgtime << " microseconds";
cout << "\nAverage Time taken by binary function: "<< bavgtime << " microseconds";
ofstream fout;
fout.open("data.csv", ios::out | ios::app);
while (fout)
{
if (pos != -1)
fout<<i<<","<<lavgtime<<","<<bavgtime<<"\n";
break;
}
fout.close();
}
return 0;
}
my code finally managed to run kinda
Anonymous
the output shows Average time for one case only
Anonymous
"Average Time taken by linear function: 4466 microseconds"
Charon
Hello
Charon
How's your day going?
Anonymous
Hiii everyone
Charon
Yeah 😔
Charon
Which language you know C or C++?
Charon
Charon
Awesome than
Charon
I just learning C++
Vasu 🩶
Please send CORE JAVA 📚 anyone
Charon
😒
Igor🇺🇦
Guys, please use private messages for personal talks. Imagine of all 10000 stated talking here