SlideShare a Scribd company logo
1F:应聘资料Proof of abilitiesProject_Euler_No_104_Pandigital_Fibonacci_ends.cs
//Project Euler #104: Pandigital Fibonacci ends
using System;
using System.Collections.Generic;
using System.IO;
class Solution
{
static bool checkk(short[] gn, short k)
{
bool contain = false;
int i = 1;
while (i <= k)
{
bool first = false;
bool last = false;
for (int j = 0; j <= k - 1; j++)
{
if (gn[j] == i)
{
first = true;
break;
//Console.WriteLine("first:"+first);
}
}
if (first == false)
{
contain = false;
break;
}
for (int j = gn.Length - 1; j > gn.Length - k - 1; j--)
{
if (gn[j] == i)
{
last = true;
break;
//Console.WriteLine("last:"+first);
}
}
if (last == false)
{
contain = false;
break;
}
if (first && last)
{
contain = true;
i++;
}
else
{
contain = false;
break;
}
}
//Console.WriteLine("contain"+contain);
return contain;
}
//adder
static short[] adder(short[] x, short[] y)
{
int digit = x.Length;
short[] outcome = new short[digit + 1];
short[] newy = new short[digit];
/*Console.WriteLine("newx:");
for (int i=0;i<digit;i++){
2F:应聘资料Proof of abilitiesProject_Euler_No_104_Pandigital_Fibonacci_ends.cs
Console.Write(newx[i]);
}
Console.WriteLine();*/
for (int i = y.Length - 1; i >= 0; i--)
{
if (y.Length < digit)
{
newy[i + 1] = y[i];
}
else
{
newy[i] = y[i];
}
}
/*Console.WriteLine("newy:");
for (int i=0;i<digit;i++){
Console.Write(newy[i]);
}
Console.WriteLine();*/
for (int i = digit - 1; i >= 0; i--)
{
short adding = (Int16)(x[i] + newy[i] + outcome[i + 1]);
if (adding >= 10)
{
outcome[i + 1] = (Int16)(adding % 10);
outcome[i] = 1;
}
else
{
outcome[i + 1] = adding;
}
}
if (outcome[0] == 0)
{
short[] modoutcome = new short[digit];
for (int i = 0; i < digit; i++)
{
modoutcome[i] = outcome[i + 1];
}
return modoutcome;
}
else
{
return outcome;
}
}
//trans int to array int
static short[] mgtran(short interger)
{
//Console.WriteLine("in:"+interger);
short[] array = new short[1];
array[0] = interger;
//Console.WriteLine("out:"+array[0]);
return array;
}
static void Main(String[] args)
{
//read
short a = Convert.ToInt16(Console.ReadLine());
short b = Convert.ToInt16(Console.ReadLine());
short k = Convert.ToInt16(Console.ReadLine());
//start to do fibo
int n = 1;
//int gnone=a;
3F:应聘资料Proof of abilitiesProject_Euler_No_104_Pandigital_Fibonacci_ends.cs
short[] gnone = mgtran(a);
//int gntwo=b;
short[] gntwo = mgtran(b);
//int gnthree=0;
short[] gnthree = mgtran(0);
while (n <= 1000000)
{
//circle fibo
switch (n)
{
case 1: gnthree = adder(gnone, new short[1]);
break;
case 2: gnthree = adder(gntwo, new short[1]);
break;
case 3: gnthree = adder(gntwo, gnone);
break;
default:
gnone = adder(gntwo, new short[1]);
gntwo = adder(gnthree, new short[1]);
gnthree = adder(gntwo, gnone);
break;
}
/*Console.WriteLine("fibo:"+n);
for (int i=0;i<gnthree.Length;i++){
Console.Write(gnthree[i]);
}
Console.WriteLine();*/
if (gnthree.Length >= k)
{
if (checkk(gnthree, k))
{
Console.WriteLine((n));
break;
}
}
n++;
}
if (n == 1000001)
{
Console.WriteLine("no solution");
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be
named Solution */
}
}

More Related Content

What's hot

C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
Chris Ohk
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
명신 김
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
Farhan Ab Rahman
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
sajidpk92
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
Farhan Ab Rahman
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
OdessaJS Conf
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
sajidpk92
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
DOSONKA Group
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
Farhan Ab Rahman
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
mohamed sikander
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
mohamed sikander
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
Farhan Ab Rahman
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
Chris Ohk
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 
Nested loops
Nested loopsNested loops
Nested loops
Adnan Ferdous Ahmed
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
Eleanor McHugh
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
Chris Ohk
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
mohamed sikander
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
Mohammad Shaker
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
Chris Ohk
 

What's hot (20)

C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
C++ Lambda and concurrency
C++ Lambda and concurrencyC++ Lambda and concurrency
C++ Lambda and concurrency
 
C++ TUTORIAL 2
C++ TUTORIAL 2C++ TUTORIAL 2
C++ TUTORIAL 2
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
Yurii Shevtsov "V8 + libuv = Node.js. Under the hood"
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Nested loops
Nested loopsNested loops
Nested loops
 
Go a crash course
Go   a crash courseGo   a crash course
Go a crash course
 
C++ Programming - 11th Study
C++ Programming - 11th StudyC++ Programming - 11th Study
C++ Programming - 11th Study
 
Implementing stack
Implementing stackImplementing stack
Implementing stack
 
C++ L07-Struct
C++ L07-StructC++ L07-Struct
C++ L07-Struct
 
C++ Programming - 4th Study
C++ Programming - 4th StudyC++ Programming - 4th Study
C++ Programming - 4th Study
 

Viewers also liked

WAQAR cv (1)
WAQAR cv (1)WAQAR cv (1)
WAQAR cv (1)
Waqar Ahmed Abbasi
 
WHAT THE HECK IS JQUERY
WHAT THE HECK IS JQUERYWHAT THE HECK IS JQUERY
WHAT THE HECK IS JQUERY
Pramesti Hatta K.
 
NCLC-395-Spring-2016-Final-Course-Evaluation
NCLC-395-Spring-2016-Final-Course-EvaluationNCLC-395-Spring-2016-Final-Course-Evaluation
NCLC-395-Spring-2016-Final-Course-Evaluation
Rebecca A. Walter
 
MARY LOU HAGEN RESUME 2015
MARY LOU HAGEN RESUME 2015MARY LOU HAGEN RESUME 2015
MARY LOU HAGEN RESUME 2015
MARY LOU HAGEN
 
十月艋舺迎青山 林金魚 台北路上觀察學會 20150429
十月艋舺迎青山 林金魚 台北路上觀察學會 20150429十月艋舺迎青山 林金魚 台北路上觀察學會 20150429
十月艋舺迎青山 林金魚 台北路上觀察學會 20150429
台北路上觀察學會 TSOC
 
Dami_CV UPDATED
Dami_CV UPDATEDDami_CV UPDATED
Dami_CV UPDATED
Damilola Omowo
 
Type out these sentences
Type out these sentencesType out these sentences
Type out these sentences
tkeizer
 
дпа з математики 2016
дпа з математики 2016дпа з математики 2016
дпа з математики 2016
Інна Терлецька
 
IVF Business Strategies in QM Models
IVF Business Strategies in QM ModelsIVF Business Strategies in QM Models
IVF Business Strategies in QM Models
Fabiola Bento
 
ORGANIZATIONAL STRUCTURE TRAINING
ORGANIZATIONAL STRUCTURE TRAININGORGANIZATIONAL STRUCTURE TRAINING
ORGANIZATIONAL STRUCTURE TRAINING
Saurabh Vishal
 
El grito de la tierra es el grito de los pobres. La enciclica Laudato Si
El grito de la tierra es el grito de los pobres. La enciclica Laudato SiEl grito de la tierra es el grito de los pobres. La enciclica Laudato Si
El grito de la tierra es el grito de los pobres. La enciclica Laudato Si
Leandro Sequeiros
 
Sabbath school lesson 11, 4th quarter of 2015
Sabbath school lesson 11, 4th quarter of 2015Sabbath school lesson 11, 4th quarter of 2015
Sabbath school lesson 11, 4th quarter of 2015
David Syahputra
 

Viewers also liked (13)

WAQAR cv (1)
WAQAR cv (1)WAQAR cv (1)
WAQAR cv (1)
 
WHAT THE HECK IS JQUERY
WHAT THE HECK IS JQUERYWHAT THE HECK IS JQUERY
WHAT THE HECK IS JQUERY
 
NCLC-395-Spring-2016-Final-Course-Evaluation
NCLC-395-Spring-2016-Final-Course-EvaluationNCLC-395-Spring-2016-Final-Course-Evaluation
NCLC-395-Spring-2016-Final-Course-Evaluation
 
MARY LOU HAGEN RESUME 2015
MARY LOU HAGEN RESUME 2015MARY LOU HAGEN RESUME 2015
MARY LOU HAGEN RESUME 2015
 
十月艋舺迎青山 林金魚 台北路上觀察學會 20150429
十月艋舺迎青山 林金魚 台北路上觀察學會 20150429十月艋舺迎青山 林金魚 台北路上觀察學會 20150429
十月艋舺迎青山 林金魚 台北路上觀察學會 20150429
 
Dami_CV UPDATED
Dami_CV UPDATEDDami_CV UPDATED
Dami_CV UPDATED
 
Type out these sentences
Type out these sentencesType out these sentences
Type out these sentences
 
дпа з математики 2016
дпа з математики 2016дпа з математики 2016
дпа з математики 2016
 
SafeMail presentation
SafeMail presentationSafeMail presentation
SafeMail presentation
 
IVF Business Strategies in QM Models
IVF Business Strategies in QM ModelsIVF Business Strategies in QM Models
IVF Business Strategies in QM Models
 
ORGANIZATIONAL STRUCTURE TRAINING
ORGANIZATIONAL STRUCTURE TRAININGORGANIZATIONAL STRUCTURE TRAINING
ORGANIZATIONAL STRUCTURE TRAINING
 
El grito de la tierra es el grito de los pobres. La enciclica Laudato Si
El grito de la tierra es el grito de los pobres. La enciclica Laudato SiEl grito de la tierra es el grito de los pobres. La enciclica Laudato Si
El grito de la tierra es el grito de los pobres. La enciclica Laudato Si
 
Sabbath school lesson 11, 4th quarter of 2015
Sabbath school lesson 11, 4th quarter of 2015Sabbath school lesson 11, 4th quarter of 2015
Sabbath school lesson 11, 4th quarter of 2015
 

Similar to Project_Euler_No_104_Pandigital_Fibonacci_ends

C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
Lập trình C
Lập trình CLập trình C
Lập trình C
Viet NguyenHoang
 
Loops
LoopsLoops
Loops
Kamran
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
kkkseld
 
Code optimization
Code optimization Code optimization
Code optimization
Code optimization Code optimization
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
Dr.M.Karthika parthasarathy
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
TAlha MAlik
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
STAMP Project
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
19magnet
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
جامعة القدس المفتوحة
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
Prabhu D
 
Ch4
Ch4Ch4
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
Timur Safin
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
ssuser3cbb4c
 
Cpp programs
Cpp programsCpp programs
Cpp programs
harman kaur
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1

Similar to Project_Euler_No_104_Pandigital_Fibonacci_ends (20)

C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Loops
LoopsLoops
Loops
 
Microsoft Word Hw#1
Microsoft Word   Hw#1Microsoft Word   Hw#1
Microsoft Word Hw#1
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
.net progrmming part1
.net progrmming part1.net progrmming part1
.net progrmming part1
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
Cs1123 8 functions
Cs1123 8 functionsCs1123 8 functions
Cs1123 8 functions
 
Mutation @ Spotify
Mutation @ Spotify Mutation @ Spotify
Mutation @ Spotify
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Compiler Optimization Presentation
Compiler Optimization PresentationCompiler Optimization Presentation
Compiler Optimization Presentation
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
Network lab manual
Network lab manualNetwork lab manual
Network lab manual
 
Ch4
Ch4Ch4
Ch4
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Cpp c++ 1
Cpp c++ 1Cpp c++ 1
Cpp c++ 1
 

Project_Euler_No_104_Pandigital_Fibonacci_ends

  • 1. 1F:应聘资料Proof of abilitiesProject_Euler_No_104_Pandigital_Fibonacci_ends.cs //Project Euler #104: Pandigital Fibonacci ends using System; using System.Collections.Generic; using System.IO; class Solution { static bool checkk(short[] gn, short k) { bool contain = false; int i = 1; while (i <= k) { bool first = false; bool last = false; for (int j = 0; j <= k - 1; j++) { if (gn[j] == i) { first = true; break; //Console.WriteLine("first:"+first); } } if (first == false) { contain = false; break; } for (int j = gn.Length - 1; j > gn.Length - k - 1; j--) { if (gn[j] == i) { last = true; break; //Console.WriteLine("last:"+first); } } if (last == false) { contain = false; break; } if (first && last) { contain = true; i++; } else { contain = false; break; } } //Console.WriteLine("contain"+contain); return contain; } //adder static short[] adder(short[] x, short[] y) { int digit = x.Length; short[] outcome = new short[digit + 1]; short[] newy = new short[digit]; /*Console.WriteLine("newx:"); for (int i=0;i<digit;i++){
  • 2. 2F:应聘资料Proof of abilitiesProject_Euler_No_104_Pandigital_Fibonacci_ends.cs Console.Write(newx[i]); } Console.WriteLine();*/ for (int i = y.Length - 1; i >= 0; i--) { if (y.Length < digit) { newy[i + 1] = y[i]; } else { newy[i] = y[i]; } } /*Console.WriteLine("newy:"); for (int i=0;i<digit;i++){ Console.Write(newy[i]); } Console.WriteLine();*/ for (int i = digit - 1; i >= 0; i--) { short adding = (Int16)(x[i] + newy[i] + outcome[i + 1]); if (adding >= 10) { outcome[i + 1] = (Int16)(adding % 10); outcome[i] = 1; } else { outcome[i + 1] = adding; } } if (outcome[0] == 0) { short[] modoutcome = new short[digit]; for (int i = 0; i < digit; i++) { modoutcome[i] = outcome[i + 1]; } return modoutcome; } else { return outcome; } } //trans int to array int static short[] mgtran(short interger) { //Console.WriteLine("in:"+interger); short[] array = new short[1]; array[0] = interger; //Console.WriteLine("out:"+array[0]); return array; } static void Main(String[] args) { //read short a = Convert.ToInt16(Console.ReadLine()); short b = Convert.ToInt16(Console.ReadLine()); short k = Convert.ToInt16(Console.ReadLine()); //start to do fibo int n = 1; //int gnone=a;
  • 3. 3F:应聘资料Proof of abilitiesProject_Euler_No_104_Pandigital_Fibonacci_ends.cs short[] gnone = mgtran(a); //int gntwo=b; short[] gntwo = mgtran(b); //int gnthree=0; short[] gnthree = mgtran(0); while (n <= 1000000) { //circle fibo switch (n) { case 1: gnthree = adder(gnone, new short[1]); break; case 2: gnthree = adder(gntwo, new short[1]); break; case 3: gnthree = adder(gntwo, gnone); break; default: gnone = adder(gntwo, new short[1]); gntwo = adder(gnthree, new short[1]); gnthree = adder(gntwo, gnone); break; } /*Console.WriteLine("fibo:"+n); for (int i=0;i<gnthree.Length;i++){ Console.Write(gnthree[i]); } Console.WriteLine();*/ if (gnthree.Length >= k) { if (checkk(gnthree, k)) { Console.WriteLine((n)); break; } } n++; } if (n == 1000001) { Console.WriteLine("no solution"); } /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */ } }