Radely James for bloomberg.
This commit is contained in:
140
interviews/radley_james/online_test.cpp
Normal file
140
interviews/radley_james/online_test.cpp
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
|
||||||
|
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
|
||||||
|
VIM: let g:argv=""
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
/*
|
||||||
|
#1 print numbers from 1 to N and if i is 3 mutltiple print "Fizz", if 5 multiple "Buzz".
|
||||||
|
If both then "FizzBuzz". Otherwise print number.
|
||||||
|
|
||||||
|
int N;
|
||||||
|
std::cin >> N;
|
||||||
|
|
||||||
|
for (int i = 1; i <= N; i++)
|
||||||
|
{
|
||||||
|
if (!(i % 3))
|
||||||
|
std::cout << "Fizz";
|
||||||
|
if (!(i % 5))
|
||||||
|
std::cout << "Buzz";
|
||||||
|
if ((i % 3) && (i % 5))
|
||||||
|
std::cout << i;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#2 print complement of N.
|
||||||
|
|
||||||
|
unsigned int c = 1;
|
||||||
|
unsigned int b = N;
|
||||||
|
while (b)
|
||||||
|
{
|
||||||
|
b >>= 1;
|
||||||
|
c <<= 1;
|
||||||
|
}
|
||||||
|
return c-1-N;
|
||||||
|
|
||||||
|
alternative:
|
||||||
|
if ( !N )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
unsigned int b = N;
|
||||||
|
while ((b&(b-1)))
|
||||||
|
auto n = b&(b-1);
|
||||||
|
return (b<<1)-1-N;
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#3
|
||||||
|
char a[] = "";
|
||||||
|
sizeof(a)?
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#4
|
||||||
|
struct A {
|
||||||
|
int x;
|
||||||
|
A(int a) : x(a) {}
|
||||||
|
A( const A& a ) { x=a.x; x++; }
|
||||||
|
opertaor = ... { x=a.x; x--; }
|
||||||
|
};
|
||||||
|
|
||||||
|
A a(4);
|
||||||
|
A b = a;
|
||||||
|
std::cout << b.x;
|
||||||
|
|
||||||
|
3?
|
||||||
|
4?
|
||||||
|
5?
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#5
|
||||||
|
struct A {
|
||||||
|
int u;
|
||||||
|
int l;
|
||||||
|
|
||||||
|
A(int i) : l(i), u(l + 1) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
A a(5);
|
||||||
|
print a.l a.u
|
||||||
|
|
||||||
|
5 6
|
||||||
|
compilation fail
|
||||||
|
5 garbage ?
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
//#6
|
||||||
|
/*
|
||||||
|
struct A {
|
||||||
|
int d;
|
||||||
|
virtual ~A(){}
|
||||||
|
};
|
||||||
|
sizeof(A)? 8 || 16
|
||||||
|
*/
|
||||||
|
|
||||||
|
//#7
|
||||||
|
/*
|
||||||
|
|
||||||
|
conceptual support for function call
|
||||||
|
|
||||||
|
system stack
|
||||||
|
data segment
|
||||||
|
processor's register
|
||||||
|
text segment
|
||||||
|
heap
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main ( void )
|
||||||
|
{try{
|
||||||
|
|
||||||
|
|
||||||
|
A a(5);
|
||||||
|
std::cout << a.l << ' ' << a.u ;
|
||||||
|
|
||||||
|
char c;
|
||||||
|
std::cin >> c;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch ( const std::exception& e )
|
||||||
|
{
|
||||||
|
std::cerr << std::endl
|
||||||
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
catch ( ... )
|
||||||
|
{
|
||||||
|
std::cerr << std::endl
|
||||||
|
<< "unknown exception." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}}
|
||||||
|
|
||||||
Reference in New Issue
Block a user