AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC114-C 755
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("575");
//4
}
else if (InputPattern == "Input2") {
WillReturn.Add("3600");
//13
}
else if (InputPattern == "Input3") {
WillReturn.Add("999999999");
//26484
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = InputList[0].Split(' ').Select(X => int.Parse(X)).ToArray();
int N = wkArr[0];
string[] wk753Arr = Derive753Arr();
int Answer = 0;
foreach (string EachStr in wk753Arr) {
if (int.Parse(EachStr) <= N) {
Answer++;
}
}
Console.WriteLine(Answer);
}
static string[] Derive753Arr()
{
var WillReturn = new List<string>();
var Stk = new Stack<string>();
Stk.Push("");
while (Stk.Count > 0) {
string Popped = Stk.Pop();
if (Popped.Contains("3") && Popped.Contains("5") && Popped.Contains("7")) {
WillReturn.Add(Popped);
}
if (Popped.Length == 9) {
continue;
}
Stk.Push(Popped + "3");
Stk.Push(Popped + "5");
Stk.Push(Popped + "7");
}
return WillReturn.ToArray();
}
}
解説
深さ優先探索を使ってます。