Coding Test
Coding Test
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <unistd.h>
#include<cmath>
while(pos<str.size())
{
pos = str.find(fndstr,pos==0?0:pos+1);
cout<<endl<<"Outer Loction "<<pos<<endl;
int y=pos/imageWidth;
int x=pos%imageWidth;
cout<<"X="<<x<<"Y="<<y;
int sx,sy,spos=0;
for(it=1;it<patternHeight;++it)
{
spos=str.find(pattern[it],spos==0?pos+1:spos+1);
cout<<endl<<it<<".Loction "<<spos<<endl;
sy=spos/imageWidth;
sx=spos%imageWidth;
cout<<it<<".X="<<sx<<"Y="<<sy;
if(sx!=x || sy!=y+it) break;
}
if(it==patternHeight)
{
cout<<endl<<it<<"-"<<patternHeight<<" X="<<x<<"Y="<<y;
return vector<int>(x,y);
}
}
return vector<int>(0,0);
}
//Loop in graph
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unistd.h>
cout<<endl<<startNodeId<<endl;
int i=1;
vector<int> v1;
int start=0;
int s=0;
int elem=startNodeId;
int elem1=startNodeId;
while(1)
{
auto temp=find(fromIds.begin(),fromIds.end(),elem1);
start=fromIds.end()-temp;
cout<<endl<<"st - "<<elem1<<"="<<*temp;
s=fromIds.size()-start;
cout<<" - "<<s;
elem=fromIds[s];
// cout<<" "<<elem;
elem1=toIds[s];
if (find(v1.begin(),v1.end(),elem1)!=v1.end()) return elem;
cout<<" "<<elem1;
}
return -1;
}
if(find(v1.begin(),v1.end(),s2)!=v1.end() )
return s2;
else if(find(v2.begin(),v2.end(),s1)!=v2.end())
return s1;
ss1=s1;
ss2=s2;
cout<<ss1<<" "<<ss2<<" "<<++i<<endl;
for (sum = 0; s1 > 0; sum += s1 % 10, s1 /= 10 );
for (sum1 = 0; s2 > 0; sum1 += s2 % 10, s2 /= 10);
s1=ss1+sum ;
s2=ss2+sum1;
// cout<<sum<<" "<<sum1<<endl;
// cout<<"s1="<<s1<<"s2="<<s2<<endl;
if(s1<0 || s1>20000000) return -1;
if(s2<0 || s2>20000000) return -1;
}
return -1;
}
// game loop
while (1) {
int width;
int height;
int length;
int mass;
cin >> width >> height >> length >> mass; cin.ignore();
int std_out_fd = dup(1);
dup2(2, 1);
string action = solve(width, height, length, mass);
dup2(std_out_fd, 1);
cout << action << endl;
}
}
/* Ignore and do not change the code above */
////Discount Sale
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unistd.h>
#include<numeric>
using namespace std;
return total;
}
return -1;
}
//change question
#include <cmath>
#include<iostream>
using namespace std;
class Answer
{
public:
static bool optimalChange(long s, Change &c)
{
c.coin2 = 0;
c.bill5 = 0;
c.bill10 = 0;
if(s<2) return false;
if(s%2!=0)
{
c.bill5=1;
s=s-5;
}
int ud=s%10;
long s1=(long)s/10;
if(ud>0)
c.coin2=ud/2;
c.bill10=s1;
return true;
}
};
///close to zero
#include <cmath>
#include<algorithm>
#include<vector>
using namespace std;
class Answer
{
public:
/// This method finds the number closest to
zero
static int closestToZero(int ints[], int size)
{
sort(ints,ints+size);
vector<int> v1(ints,ints+size);
vector<int>::iterator it;
if(ints[0]>0) return ints[0];
else if (ints[size-1]<0) return ints[size-1];
else{
it=partition_point(v1.begin(),v1.end(),[](int x){
return x<0;
}
);
return *it;
}
return 0;
}
};
//find greatest
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Algorithm
{
public:
/** @return the largest number in the given array*/
static int findLargest(int numbers[], int length)
{
vector<int> vect(numbers,numbers+length);
return *max_element(vect.begin(),vect.end());
}
};
return 0;
}
//Last Occurence
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
std::string s = "Hello World!Hello";
std::string s1 = "Hello";
return 0;
}
////Value of PI
#include <vector>
#include<algorithm>
#include<iostream>