einstein010
BAN USERThe question is very unclear. Mukund's solution will not work if the file contains 1 2 4 5 ...here the missing number in the file is 3 and not max+1 which is 6
- einstein010 April 18, 2011<pre lang="" line="1" title="CodeMonkey75884" class="run-this">// I dont know why people make easy things complicated
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int n;
vector<int> num;
while(cin>>n){
if(n==0)
break;
else
num.push_back(n);
}
sort(num.begin(),num.end());
unsigned long long result=0;
for(int i=0;i<num.size()-3;i++){
result += num[i];
}
cout<<(double)result/(num.size()-3)<<endl;
return 0;
}</pre>
I dont think anybody noticed that in street the space is after the 'e' and not 'r'...length/2 would give you the wrong answer
- einstein010 April 18, 2011I could not assume that the array was sorted...So I sorted the array and wrote the code as per the technique proposed by amit5624.. The interviewer completely ignored it and asked me to write code for a self balancing binary search tree instead..so i wrote the insert function for avl tree
- einstein010 April 18, 2011<pre lang="" line="1" title="CodeMonkey54817" class="run-this">#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
using namespace std;
int main(){
string line;
getline(cin,line);
istringstream iss(line);
string result="";
while(iss){
string sub;
iss>>sub;
if(sub!=""){
if(sub == "a"){
result+="the ";
}
else
result+=sub+ " ";
}
}
cout<<result<<endl;
return 0;
}</pre>
<pre lang="" line="1" title="CodeMonkey38712" class="run-this">// Perfect number
- einstein010 April 18, 2011// Using trial Division technique
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> factors;
factors.push_back(1);
for(int i=2;i*i<=n;i++){
if(n%i==0){
factors.push_back(i);
factors.push_back(n/i);
}
}
int result=0;
for(int i=0;i<factors.size();i++){
result+=factors[i];
}
if(result==n)
cout<<"Perfect Number"<<endl;
else
cout<<"Not a perfect number"<<endl;
return 0;
}</pre>