shravan40
BAN USERHello all, I am Shravan Kumar Gond from Varanasi. I am 4th UG student at IIT Kharagpur. I am from Department of Mathematics enrolled in it's integrated M.Sc ( 5 year ) course of Mathematics and Computing. I like to play Cricket and card games. I love coding.
1. Take input as 2-d array.
2. Copy all the element of of given matrix into 1-D array of size n^2
3. Sort the array using quick/merge or any other sorting algorithm.
4. print all the element of 1-D array separated by comma.
// here is the implemented algorithm
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int array [n][n];
for(int i = 0 ; i < n; i++)
{
for(int j = 0; j < n; j++)
{
cin>>array[i][j];
}
}
int arr[n*n];
int k = 0;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
arr[k] = array[i][j];
k++;
}
}
sort(arr,arr+k);
for(int i = 0; i < (n*n-1); i++)
{
cout<<arr[i]<<",";
}
cout<<arr[n*n-1];
return 0;
}
// If we rotate the Matrix of nxm by 90* then it will become matrix of mxn
// We will have to create a new 2-D array , like this rot_arr [row][col]
void rotate(int row int col, int arr[][row],int rot_arr[][col])
{
for(int j = 1; j < row; j++)
{
for (int i = m-1 , k = 0; i >= 0, k < m; i--, k++)
{
arr_rot[j][k] = arr[j][i];
}
}
}
Thanks for pointing out my mistake.
I was missing such case. I edited for my answer considering all possibilities, please have a look.
By the way i have only this code into my previous code
else if(idx > 0)
{
int l = b.length();
string temp="";
temp = a.substr(0,idx);
a = a.substr(idx+l);
cout<<temp<<a<<"\n";
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a,b; // I will take both string input from user and check whether b is substing of a or not.
cin>>a;
cin>>b;
int idx = 0;
idx = a.find(b); // Checking whether b is substring of a.
if(idx == 0)
{
int l = b.length();
a = a.substr(l);
cout<<a<<"\n";
}
else if(idx > 0)
{
int l = b.length();
string temp="";
temp = a.substr(0,idx);
a = a.substr(idx+l);
cout<<temp<<a<<"\n";
}
else
{
cout<<"-1\n";
}
return 0;
}
In the setdptr function in class base, you don't have the derived class fulle defined yet so the compiler doesn't yet know what members are in derived.
Move the actual definition of setdptr to after the declaration of derived and it should work.
Something like this:
class derived;
class base
{
// ....
void setdptr(derived* dptr);
// ....
};
class derived : public base
{
// ....
};
void base::setdptr(derived* dptr)
{
m_dptr = dptr;
dptr->sayHello();
}
string str1 ;
string str2;
int l_1 = str1.length();
int l_2 = str2.length();
if (l_1 != l_2)
{
printf("false\n");
}
else
{
int i;
int flag = 0;
for(i = 0; i < l_1; i++)
{
if( str1[i] != str2[i])
{
flag = 0;
break;
}
else
{
flag = 1;
}
}
if ( flag == 0)
{
printf("false\n");
}
else
{
printf("yes\n");
}
}
If you think you have enough caliber to get more salary than they offer at your campus then you should go for intern. Because amazon is also a good company. If you do well during your internship period then they will surely offer you PPO i.e. ( Pre - Placement Offer ) with better salary than what you will get at your college.
Correct me if i am wrong.
This code is not working you forgot to add header file for malloc. You will have to add
#include<malloc.h>
in the starting of code.
after that code is working fine. Complete running code at my terminal.
#include<iostream>
#include<malloc.h>
using namespace std;
struct node{
int a,b;
};
typedef struct node Node;
void swap(void *a,void *b){
void *temp;
temp=a;
a=b;
b=temp;
}
int main() {
Node *a1,*b1;
a1=(Node*)malloc(sizeof(Node));
b1=(Node*)malloc(sizeof(Node));
a1->a=10;
a1->b=20;
b1->a=30;
b1->b=40;
cout<<a1->a<<" "<<a1->b<<endl;
cout<<b1->a<<" "<<b1->b<<endl;
swap(a1,b1);
cout<<a1->a<<" "<<a1->b<<endl;
cout<<b1->a<<" "<<b1->b;
return 0;
}
For the First problem
Sum of { 1,2,.....,10} = 55
Add all the number in array and subtract it from 55 you will get the missing Number.
For the Second problem
Let the Two value a & b are missing
Int temp = product of all number in that array
a*b = 10 ! / temp
now you can easily guess the product of two number.
Actually my answer was for the starting case and for 2nd case too. You will have to offer only on average price or if it is in fraction Least integer of that amount. If you are offer users to play without replacement then average will change in every new trail. Otherwise it will be remain same.
- shravan40 March 12, 2013make two empty stack. Push all the string in a stack
suppose the stack name is s in which you want to push
for(i=1;i<size+1;i++) {
b=s.pop();
int k=b.compareTo(max);
if(k>0) {
max=b;
}
t.push(b);
}
System.out.print(max+" ");
for(i=1;i<size+1;i++) {
b=t.pop();
s.push(b);
}
2nd string is the sub-string of 1st string. For getting the position from where 2nd string start.
in java
here i am taking 1st string as a and 2nd string as b.
a=o.readLine();a=a.trin(); // taking input of 1st string
b=o.readLine();b=b.trim(); // taking input of 2nd string
String c=b.substring(0,1); // find the first word of 2nd strig
Int i=a.indexOf('c'); // finding the index from where 2nd string start in the 1st string
Add All the number of given array
- shravan40 December 11, 2013Let's say it's sum is K
Now we know , {1,2,3,4,5,......n} is an Arithmetic series with a = 1, d = 1
it's sum is K' = (n x (n+1) / 2)
Now the missing element can easily be obtained from subtracting K from K'
i.e. missing number/element = K' - K