DELIMITER ;;
CREATE TRIGGER `messagelists` BEFORE`messagelists` UPDATE ON `messagelists` FOR EACH ROW
BEGIN
SET NEW.messagedate = NOW();
END;;
DELIMITER ;
0xhex
7 Mayıs 2017 Pazar
MySql Adding Trigger Query
16 Kasım 2013 Cumartesi
Tail Function
void monster::monstermove(player * player1) {
if(abs(player1->m_x - m_x) < 10 && abs(player1->m_y - m_y) < 10)
return;
if(!CanMove())
return;
float tangent;
m_yvel = 4;
m_xvel=4;
if(abs(player1->m_y - this->m_y) < 10) m_yvel=0;
if(abs(player1->m_x - this->m_x) < 10) m_xvel=0;
tangent = (player1->m_y - this->m_y) / (player1->m_x - this->m_x) ;
this->m_yvel *= (abs(sinf(atan(tangent))));
this->m_xvel *= (abs(cosf(atan(tangent))));
if(player1->m_x - this->m_x > 0 && player1->m_y - this->m_y < 0) {
m_yvel*=-1;
}else if(player1->m_x - this->m_x < 0 && player1->m_y - this->m_y> 0) {
m_xvel*=-1;
}else if(player1->m_x - this->m_x < 0 && player1->m_y - this->m_y< 0) {
m_yvel*=-1;
m_xvel*=-1;
}
this->m_y += m_yvel;
this->m_x += m_xvel; //* (player1->m_x - this->m_x>0 && m_xvel >0 ?1:-1);
}
if(abs(player1->m_x - m_x) < 10 && abs(player1->m_y - m_y) < 10)
return;
if(!CanMove())
return;
float tangent;
m_yvel = 4;
m_xvel=4;
if(abs(player1->m_y - this->m_y) < 10) m_yvel=0;
if(abs(player1->m_x - this->m_x) < 10) m_xvel=0;
tangent = (player1->m_y - this->m_y) / (player1->m_x - this->m_x) ;
this->m_yvel *= (abs(sinf(atan(tangent))));
this->m_xvel *= (abs(cosf(atan(tangent))));
if(player1->m_x - this->m_x > 0 && player1->m_y - this->m_y < 0) {
m_yvel*=-1;
}else if(player1->m_x - this->m_x < 0 && player1->m_y - this->m_y> 0) {
m_xvel*=-1;
}else if(player1->m_x - this->m_x < 0 && player1->m_y - this->m_y< 0) {
m_yvel*=-1;
m_xvel*=-1;
}
this->m_y += m_yvel;
this->m_x += m_xvel; //* (player1->m_x - this->m_x>0 && m_xvel >0 ?1:-1);
}
3 Kasım 2013 Pazar
SDL Library - Tetris Game
#include "SDL.h"
#include "glut.h"
#include <iostream>
#include <string>
#include <Windows.h>
#include <SDL_opengl.h>
#include "ball.h"
#include <SDL_image.h>
struct brick{
float x;
float y;
float width;
float height;
bool alive;
};
GLuint loadTexture( const std::string &fileName )
{
SDL_Surface *image = IMG_Load( fileName.c_str() );
SDL_DisplayFormatAlpha(image);
unsigned object(0);
glGenTextures(1, &object);
glBindTexture(GL_TEXTURE_2D, object);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
//Free surface
SDL_FreeSurface(image);
return object;
}
bool iscollission(float ballx,float bally,float ballH,float ballL,float ourx,float oury,float ourH,float ourL);
int main( int argc, char* args[] )
{
//initialize SDL
SDL_Init(SDL_INIT_EVERYTHING);
//Set OpenGL memory usage
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute( SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
//Caption of the window
SDL_WM_SetCaption( "Our first game", NULL );
//Size of the window
SDL_SetVideoMode(600,400,32, SDL_OPENGL );
//Specific the clear color
glClearColor(1,1,1,1); //RED,GREEN,BLUE,ALPHA
//What portion of the screen we will display
glViewport(0,0,600,400);
//Shader model - Use this
glShadeModel(GL_SMOOTH);
//2D rendering
glMatrixMode(GL_PROJECTION);
//"Save" it
glLoadIdentity();
//Disable depth checking
glDisable(GL_DEPTH_TEST);
std::cout << "OpenGL is running\n";
std::cout << "Main loop has started\n";
//Handles the main loop
bool isRunning = true;
//For handling with event
SDL_Event event;
float myX = 300; //starting x position of rectangle
float myY = 370; //starting y position of rectangle
float width = 80; //width of the rectangle
float height = 20; //height of the rectangle
bool left = false,right = false; //we save in which state the button is
//The ball variables
float ballX = 50; //x position
float ballY = 150; //y position
float ballWH = 30; //width and height of the ball
float vellX = 0.2; //x speed
float vellY = 0.2; //y speed
const int brCOUNT = 45;
brick bricks[brCOUNT];
for(int i=0,x=4,y=4;i<brCOUNT;i++,x+=66) {
if(x>560) {
x=4;
y+=30;
}
bricks[i].x = x; //Set currents bricks x position
bricks[i].y = y; //Y position
bricks[i].width = 60; //Width
bricks[i].height = 20; //Heigh
bricks[i].alive = true;
}
//Create an texture
unsigned int pad_texture = 0;
//Load the image into the texture using the function
pad_texture = loadTexture("line.png");
//Main game loop
while ( isRunning )
{
//EVENTS
while ( SDL_PollEvent(&event) )
{
//if the window was closed
if ( event.type == SDL_QUIT )
{
isRunning = false;
}
//If a button was released and the button is escape
if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE )
{
isRunning = false;
}
if ( event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_r )
{
glClearColor(1,0,0,1);
}
if ( event.type == SDL_KEYDOWN ) //Check for presed down buttons
{
if ( event.key.keysym.sym == SDLK_LEFT ) //Check left key
{
left = true; //Set the boolean value for left key to true (it is pressed)
}
else if ( event.key.keysym.sym == SDLK_RIGHT ) //Check Right key
{
right = true; //Set the boolean value for right key to true (it is pressed)
}
}
else if ( event.type == SDL_KEYUP ) //Checking for released buttons
{
if ( event.key.keysym.sym == SDLK_LEFT ) //Left key
{
left = false; //Set the value to false (key is released)
}
else if ( event.key.keysym.sym == SDLK_RIGHT ) //Right key
{
right = false; //Key is released
}
}
//logic that should happen for a certain event
}
//LOGIC
if ( left == true ) //If left key is pressed
{
myX -= 0.5; //Move left
}
if ( right == true ) //If right key is pressed
{
myX += 0.5; //Move right
}
if ( myX < 0 ) //If the left border of the pad is over the left part of the screen
{
myX = 0; //Put the pad back so it isn't over the border
}
if ( myX+width > 600 ) //If the pad is over the right border of the screen
{
myX = 600-width; //Move it back so it only touches the right border
}
//The ball logic
ballX += vellX; //Move the ball on x axis
ballY += vellY; //move the ball on y axis
if ( ballX < 0 ) //Check if the ball hit the left edge of screen
{
vellX = -vellX; //negate the x velocity
}
else if ( ballX+ballWH>600 )
{
vellX = -vellX;
}
if ( ballY < 0 )
{
vellY = -vellY;
}
else if ( ballY+ballWH > 400 ) //if the ball hit the bottom edge of screen
{
isRunning = false; //close game
}
if(iscollission(ballX,ballY,ballWH,ballWH,myX,myY,height,width)) {
vellY = -vellY;
}
for(int i=0;i<brCOUNT;i++) {
if(bricks[i].alive) {
if(iscollission(bricks[i].x,bricks[i].y,bricks[i].height,bricks[i].width,ballX,ballY,ballWH,ballWH)) {
bricks[i].alive = false;
vellY = -vellY;
break;
}
}
}
//RENDERING to the screen
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); //Start rendering phase
glOrtho(0,600,400,0,-1,1); //Set the matrix
glColor4ub(255,255,255,255); //White color
//Enable textures when we are going to blend an texture
glEnable(GL_TEXTURE_2D);
//What texture we are going to use
glBindTexture(GL_TEXTURE_2D,pad_texture);
glBegin(GL_QUADS); //Start drawing the pad
//We set the corners of the texture using glTexCoord2d
glTexCoord2d(0,0); glVertex2f(myX,myY); //Upper-left corner
glTexCoord2d(1,0); glVertex2f(myX+width,myY); //Upper-right corner
glTexCoord2d(1,1); glVertex2f(myX+width,myY+height); //Down-right corner
glTexCoord2d(0,1); glVertex2f(myX,myY+height); //Down-left corner
glEnd(); //End drawing
glColor4ub(255,0,0,255); //Red color
glBegin(GL_QUADS); //Render of the ball, same method as for the pad
glVertex2f(ballX,ballY);
glVertex2f(ballX+ballWH,ballY);
glVertex2f(ballX+ballWH,ballY+ballWH);
glVertex2f(ballX,ballY+ballWH);
glEnd();
for(int i=0;i<brCOUNT;i++) {
if(bricks[i].alive != true) continue;
if(i%9==0) glColor4ub(i*5,i*5,0,1);
glBegin(GL_QUADS);
glVertex2f(bricks[i].x,bricks[i].y);
glVertex2f(bricks[i].x+bricks[i].width,bricks[i].y);
glVertex2f(bricks[i].x+bricks[i].width,bricks[i].y+bricks[i].height);
glVertex2f(bricks[i].x,bricks[i].y+bricks[i].height);
glEnd();
}
glPopMatrix(); //End rendering phase
SDL_GL_SwapBuffers();
SDL_Delay(1); //Delay / pause
}
SDL_Quit();
return 0;
}
bool iscollission(float ballx,float bally,float ballH,float ballW,float ourx,float oury,float ourH,float ourW) {
if(bally+ballH < oury) return false;
else if(ourx>ballx+ballW) return false;
else if(ourx+ourW < ballx) return false;
else if(oury+ourH < bally) return false;
return true;
}
15 Mayıs 2013 Çarşamba
Current getDate seperate by seperate
#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string>
#include <ctime>
using namespace std;
int getMonth(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
return timeinfo->tm_mon + 1;
}
int getDay(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
return timeinfo->tm_mday;
}
int getYear(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
return timeinfo->tm_year+1900;
}
int getHour(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
return timeinfo->tm_hour;
}
int getMin(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
return timeinfo->tm_min;
}
int getSec(time_t timeval){
struct tm * timeinfo;
timeinfo = localtime(&timeval);
return timeinfo->tm_sec;
}
string getWeekday(time_t timeval){
struct tm * timeinfo;
string days[7] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
//could just make this global
timeinfo = localtime(&timeval);
return days[timeinfo->tm_wday];
}
string getmonth(time_t timeval){
struct tm * timeinfo;
string days[12] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
//could just make this global
timeinfo = localtime(&timeval);
return days[timeinfo->tm_mon];
}
int main()
{
/*time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
printf ("Current local time and date: %s", asctime(timeinfo));
*/
cout << "Date :" << getMonth(time(0)) << "/" << getDay(time(0)) << "/" << getYear(time(0)) << "-" << getWeekday(time(0)) << "\nClock:" << getHour(time(0)) << ":" << getMin(time(0)) << ":" << getSec(time(0)) << endl ;
system("pause");
return 0;
}
10 Nisan 2013 Çarşamba
XOX Game
Multiplayer Game
Single Game
#include "stdafx.h"
#include <iostream>
#include "efe.h"
#include <ctime>
using namespace std;
int main()
{
mainscreen();
system("pause");
return 0;
}
-----------efe.h---------
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
void computer(char player,char computer);
void sender(char player);
void multiplayer(char playerone);
void checkermulti();
void show(char dizi[3][3],char turn);
void checker(char dizi[3][3],char computer,char player);
char dizi[3][3],efee;int turn=0;
bool efe=1,mltplyr=0;
void mainscreen() {
srand(time(NULL));
system("cls");
for(int i=0;i<3;i++) {
for(int k=0;k<3;k++) {
dizi[i][k] = '-';
}
}
char choosee[10];
char choose;
string str;
cout << " ############################################" << "\n" << " #" << " XOX Game Version 1.0.0 " << "#\n" << " #" << " Written by 0xhex " << "#\n" " ############################################" << "\n";
cout << "If you want to play with computer press 1" << endl;
cout << "If you want to play with your friend press 2" << endl; cin >> choose;
if(choose==49) {
cout << "Which do you prefer X or O" << endl;
do {
cin >> choosee;
choose=choosee[0];
if(choose!='X' && choose!='O') cout << "Enter X or O" << endl;
}while(choose!='X' && choose!='O');
if(choose=='X') {
show(dizi,choose);
do {computer('X','O'); }while(efe==1);
}else {
show(dizi,choose);
do {computer('O','X'); }while(efe==1);
}
}else if(choose==50) {
cout << "Player-one,what will be? X or O:";
do {
cin >> choose;
if(choose!='X' && choose!='O') cout << "Enter X or O" << endl;
}while(choose!='X' && choose!='O');
multiplayer(choose);
}else {
system("cls");
mainscreen();
}
}
void sender(char player) {
int row,coloumn;
bool res=0;
cout << endl;
do {
do {
cout << " Which row?(1,2,3) :" ;
cin >> row;
if(row!=1 && row!=2 && row!=3) cout << "Please enter number between 0 and 4 (1,2,3)";
}while(row!=1 && row!=2 && row!=3);
do {
cout << " Which coloumn?(1,2,3) :";
cin >> coloumn;
if(coloumn!=1 && coloumn!=2 && coloumn!=3) cout << "Please enter number between 0 and 4 (1,2,3)";
}while(coloumn!=1 && coloumn!=2 && coloumn!=3);
if(dizi[row-1][coloumn-1]=='-') {
dizi[row-1][coloumn-1]=player;
break;
}else {
cout << " This area full please enter another choose" << endl;
}
}while(true);//player turn over here!!!
if(dizi[0][0]!='-' && dizi[0][1]!='-' && dizi[0][2]!='-' && dizi[1][0]!='-' && dizi[1][1]!='-' && dizi[1][2]!='-' && dizi[2][0]!='-' && dizi[2][1]!='-' && dizi[2][2]!='-') {
efe=0;
show(dizi,player);
cout << " No Winner!" << endl;
cout << " Do you wanna play again? (y/n)" << endl;
int x;
do {
cout << " ";
cin >> x;
if(x==0) { exit(0); };
if(x!=1 && x!=0) { cout << " please enter 1 or 0" << endl; }else {
if(x==1) { mainscreen(); break;}
}
}while(x!=1 && x!=0);
}
}
void computer(char player,char computer) {
sender(player);
checker(dizi,computer,player); //turn is computer
show(dizi,player);
if(efe==0) {
cout << " Winner Computer" << endl;
cout << " Do you wanna play again?(again:1-exit:0)" << endl;
int x;
do {
cout << " ";
cin >> x;
if(x==0) { exit(0); };
if(x!=1 && x!=0) { cout << " please enter 1 or 0" << endl; }else {
if(x==1) { mainscreen(); break;}
}
}while(x!=1 && x!=0);
}
turn++;
}
void show(char dizi[3][3],char player) {
cout << endl;
cout << " " << "1 " << "2 " << "3" << endl;
for(int i=0;i<3;i++) {
cout << " ";
if(i==0) cout << "1";
if(i==1) cout << "2";
if(i==2) cout << "3";
for(int k=0;k<3;k++) {
if(dizi[i][k]=='-') {
cout << "[" << dizi[i][k] << "]";
}else {
cout << "[" << dizi[i][k] << "]";
}
}
cout << endl;
}
if(efe==1) {
cout << endl;
cout << " Turn is " << player << ";";
}
}
void checker(char dizi[3][3],char computer,char player) {
if(turn==0) { //if first round and middle is empty ; give &computer into middle
if(dizi[1][1]=='-') {
dizi[1][1]=computer;
return;
}
}
if(dizi[1][1]==dizi[0][2] && dizi[1][1]==computer && dizi[2][0] == '-') { dizi[2][0] = computer; efe=0; return;
}else if(dizi[1][1]==dizi[2][0] && dizi[1][1]==computer && dizi[0][2] == '-') { dizi[0][2] = computer; efe=0; return;
}else if(dizi[2][0]==dizi[0][2] && dizi[2][0]==computer && dizi[1][1] == '-') { dizi[1][1] = computer; efe=0; return;
}else if(dizi[1][1]==dizi[0][0] && dizi[1][1]==computer && dizi[2][2] == '-') { dizi[2][2] = computer; efe=0; return;
}else if(dizi[1][1]==dizi[2][2] && dizi[1][1]==computer && dizi[0][0] == '-') { dizi[0][0] = computer; efe=0;return;
}else if(dizi[0][0]==dizi[2][2] && dizi[2][2]==computer && dizi[1][1] == '-') { dizi[1][1] = computer; efe=0; return;}
for(int i=0;i<3;i++) {
if(dizi[i][0] == dizi[i][2] && dizi[i][0]==computer && dizi[i][1] =='-') { // first and third check //row checker here!!!
dizi[i][1] = computer; efe=0; return;
}else if(dizi[i][0] == dizi[i][1] && dizi[i][1]==computer && dizi[i][2] =='-') { // first and second check
dizi[i][2] = computer; efe=0; return;
}else if(dizi[i][1] == dizi[i][2] && dizi[i][1]==computer && dizi[i][0] =='-') { // second and third check
dizi[i][0] = computer; efe=0; return;
}
}
for(int i=0;i<3;i++) {
if(dizi[0][i] == dizi[2][i] && dizi[0][i]==computer && dizi[1][i] =='-') { // first and third check //coloumn checker here!!!
dizi[1][i] =computer; efe=0 ; return;
}else if(dizi[0][i] == dizi[1][i] && dizi[1][i]==computer && dizi[2][i] =='-') { // first and second check
dizi[2][i] =computer; efe=0;return;
}else if(dizi[1][i] == dizi[2][i] && dizi[1][i]==computer && dizi[0][i] =='-') { // second and third check
dizi[0][i] =computer; efe=0;return;
}
}
if(dizi[1][1]==dizi[0][2] && dizi[1][1]==player && dizi[2][0] == '-') { dizi[2][0] = computer; return;
}else if(dizi[1][1]==dizi[2][0] && dizi[1][1]==player && dizi[0][2] == '-') { dizi[0][2] = computer; return;
}else if(dizi[2][0]==dizi[0][2] && dizi[2][0]==player && dizi[1][1] == '-') { dizi[1][1] = computer; return;
}else if(dizi[1][1]==dizi[0][0] && dizi[1][1]==player && dizi[2][2] == '-') { dizi[2][2] = computer; return;
}else if(dizi[1][1]==dizi[2][2] && dizi[1][1]==player && dizi[0][0] == '-') { dizi[0][0] = computer; return;
}else if(dizi[0][0]==dizi[2][2] && dizi[2][2]==player && dizi[1][1] == '-') { dizi[1][1] = computer; return; }
for(int i=0;i<3;i++) {
if((dizi[i][0] == dizi[i][2]) && dizi[i][0]==player && dizi[i][1] =='-') { // first and third check //row checker here!!!
dizi[i][1]=computer; return;
}else if((dizi[i][0] == dizi[i][1]) && dizi[i][1]==player && dizi[i][2] =='-') { // first and second check
dizi[i][2] =computer; return;
}else if((dizi[i][1] == dizi[i][2]) && dizi[i][1]==player && dizi[i][0] =='-') { // second and third check
dizi[i][0] =computer; return;
}
}
for(int i=0;i<3;i++) {
if((dizi[0][i] == dizi[2][i]) && dizi[0][i]==player && dizi[1][i] =='-') { // first and third check //coloumn checker here!!!
dizi[1][i] =computer; return;
}else if((dizi[0][i] == dizi[1][i]) && dizi[1][i]==player && dizi[2][i] =='-') { // first and second check
dizi[2][i] =computer; return;
}else if((dizi[1][i] == dizi[2][i]) && dizi[1][i]==player && dizi[0][i] =='-') { // second and third check
dizi[0][i] =computer;return;
}
}
int x=0,y=0;
do{
x=rand()%3; Sleep(35);
y=rand()%3;
if(dizi[x][y]=='-') {
dizi[x][y]=computer;
break;
return;
}
}while(true);
}
void multiplayer(char playerone) {
char playertwo;
if(playerone=='X') {
playertwo='O';
}else {
playertwo='X';
}
do {
if(turn%2==0) {
show(dizi,playerone);
sender(playerone);
checkermulti();
}else{
show(dizi,playertwo);
sender(playertwo);
checkermulti();
}
turn++;
}while(efe==1);
show(dizi,playertwo); // there is winner and last show last situation
if(efee==3) {
cout << " No Winner!" << endl;
}else {
cout << " Winner " << efee << "!" << endl;
}
cout << " Do you wanna play again?(again:1-exit:0)" << endl;
int x;
do {
cout << " ";
cin >> x;
if(x==0) { exit(0); };
if(x!=1 && x!=0) { cout << " please enter 1 or 0" << endl; }else {
if(x==1) { mainscreen(); break;}
}
}while(x!=1 && x!=0);
}
void checkermulti() {
for(int i=0,k=0;i<3;i++) {
if(dizi[i][k] == dizi[i][k+1] && dizi[i][k+1] == dizi[i][k+2] && dizi[i][k+1] != '-') { //from right to left
//Winner
efe=0;
efee=dizi[i][k];
return;
}
}
for(int i=0,k=0;i<3;i++) {
if(dizi[k][i] == dizi[k+1][i] && dizi[k+1][i] == dizi[k+2][i] && dizi[k+1][i] != '-') { //from up to down
//Winner
efe=0;
efee=dizi[k][i];
return;
}
}
if(dizi[1][1] == dizi[2][0] && dizi[1][1] == dizi[0][2] && dizi[1][1] != '-') { //cross
//Winner
efe=0;
efee=dizi[1][1];
return;
}
if(dizi[1][1] == dizi[0][0] && dizi[1][1] == dizi[2][2] && dizi[1][1] != '-') { //cross
//Winner
efe=0;
efee=dizi[1][1];
return;
}
if(dizi[0][0]!='-' && dizi[0][1]!='-' && dizi[0][2]!='-' && dizi[1][0]!='-' && dizi[1][1]!='-' && dizi[1][2]!='-' && dizi[2][0]!='-' && dizi[2][1]!='-' && dizi[2][2]!='-') {
efe=0;
efee=3;
}
};
2 Nisan 2013 Salı
Fourty nineth solution of Project Euler - Prime permutations
#include "stdafx.h"
#include <iostream>
#include<stdio.h>
#include <cmath>
#include <time.h>
using namespace std;
bool prime(unsigned long long y);
bool prime(unsigned long long y) {
for (unsigned long long i = 3; i <= (int) sqrt((double) y); i++) {
if (y % i == 0)
return 0;
}
return 1;
}
bool issamedigit(int x,int y) {
int seq[4],seqq[4];
int c=0;
do {
seq[c]=x%10;
x/=10;
c++;
}while(x>0);
c=0;
do {
seqq[c]=y%10;
y/=10;
c++;
}while(y>0);
for(int i=0;i<4;i++) {
if(seq[i]!=seqq[0] && seq[i]!=seqq[1] && seq[i]!=seqq[2] && seq[i]!=seqq[3]) {
return 0;
}
}
for(int i=0;i<4;i++) {
if(seqq[i]!=seq[0] && seqq[i]!=seq[1] && seqq[i]!=seq[2] && seqq[i]!=seq[3]) {
return 0;
}
}
return 1;
}
void make() {
for(int i=1001;i<9999;i+=2) {
if(prime(i)==1) {
for(int k=i+2;k<9999;k+=2) {
if(prime(k)==1 && issamedigit(i,k)==1) {
int m=k+(k-i);
if(m<9999 && prime(m)==1 && issamedigit(k,m)==1 && i>2000) {
cout << "Project Euler - Problem 49(Prime permutations)\n";
cout << "Result :" <<i << k << m << " efekanpulatli.blogspot.com" << endl;
return;
}
}
}
}
}
}
int main() {
clock_t tStart = clock();
make();
printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
system("pause");
return 0;
}
Fortieth solution of Project Euler - Champernowne's constant
#include "stdafx.h"
#include <iostream>
#include<stdio.h>
#include <cmath>
#include <time.h>
using namespace std;
int digit(int y) {
int c=0;
do {
y/=10;
c++;
}while(y>0);
return c;
}
void make() {
int c,k=-1,m,counter=0;
int dizi[10];
dizi[6] = 0;
for(int i=1;i<900000;i++) {
if(dizi[6]!=0) break;
c=i;
m=0;
k+=digit(i);
do {
if((k-m)+1==1 || (k-m)+1==10 || (k-m)+1 == 100 || (k-m)+1==1000 || (k-m)+1==10000 || (k-m)+1==100000 || (k-m)+1==1000000) {
dizi[counter]=c%10;
counter++;
}
c/=10;
m++;
}while(c>0);
}
int result=1;
for(int i=0;i<7;i++) {
result*=dizi[i];
}
cout << "Project Euler - Problem 40(Champernowne's constant)\n";
cout << "Result :" <<result << " efekanpulatli.blogspot.com" << endl;
}
int main() {
clock_t tStart = clock();
make();
printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
system("pause");
return 0;
}
Kaydol:
Yorumlar (Atom)








