Created
October 19, 2014 08:22
-
-
Save kuuso/2791b8656e339fbdbf0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Collections; | |
using System.Collections.Generic; | |
class TEST{ | |
static void Main(){ | |
String InputFile="./data.utf8.txt"; | |
StreamReader SR=new StreamReader(InputFile); | |
//Stream stdin=Console.OpenStandardInput(); | |
//StreamReader SR=new StreamReader(stdin); | |
String s=""; | |
List<String> L=new List<String>(); | |
while(!String.IsNullOrEmpty(s=SR.ReadLine())){ | |
var ss=s.Split('\t'); | |
Sol mySol =new Sol(ss); | |
bool chk=mySol.Solve(); | |
if(!chk)L.Add(ss[0]); | |
} | |
Console.WriteLine(""); | |
Console.WriteLine("Answer--result does not match with expectation -Total {0}",L.Count); | |
for(int i=0;i<L.Count;i++){ | |
Console.Write(i==0?"{0}":",{0}",L[i]); | |
} | |
Console.WriteLine(""); | |
} | |
} | |
class Sol{ | |
public bool Solve(){ | |
//解いた答えと期待値を比較 | |
return SolveTriangle()==ans; | |
} | |
//三角形を確定 | |
String SolveTriangle(){ | |
Triangle T=new Triangle(); | |
//条件を入力 | |
SetCondition(T); | |
//判定していく | |
if(T.Angle[0]==T.Angle[1] && T.Angle[1]==T.Angle[2]){ | |
//3つの角度が等しい⇒正三角形 | |
return "あ"; | |
} | |
if(T.Edge[0]==T.Edge[1] && T.Edge[1]==T.Edge[2]){ | |
//3つの辺が等しい⇒正三角形 | |
return "あ"; | |
} | |
if(T.Angle[0]==T.Angle[1] || T.Angle[1]==T.Angle[2] || T.Angle[2]==T.Angle[0]){ | |
//2つの角が等しい(3つとも等しい場合はすでに除外)⇒二等辺三角形 | |
return "い"; | |
} | |
if(T.Edge[0]==T.Edge[1] || T.Edge[1]==T.Edge[2] || T.Edge[2]==T.Edge[0]){ | |
//2辺が等しい⇒二等辺三角形または正三角形 | |
// 60度が一つでもあれば正三角形となる | |
for(int i=0;i<3;i++){ | |
if(T.Angle[i]==60){ | |
return "あ"; | |
} | |
} | |
return "い"; | |
} | |
return "う"; | |
} | |
Dictionary<String,int> Identifier; | |
void SetupIdentifier(){ | |
Identifier=new Dictionary<String,int>(); | |
Identifier["角A"]=0; | |
Identifier["角B"]=1; | |
Identifier["角C"]=2; | |
Identifier["AB"]=0; | |
Identifier["BC"]=1; | |
Identifier["CA"]=2; | |
Identifier["BA"]=0; | |
Identifier["CB"]=1; | |
Identifier["AC"]=2; | |
} | |
void SetCondition(Triangle t){ | |
//下準備 | |
SetupIdentifier(); | |
for(int i=0;i<conditions.Length;i++){ | |
var s=conditions[i].Split('='); | |
//今回、単位はcmと度しかないので、parseは適当 | |
int val=0; | |
if(s[1][s[1].Length-1]=='度')val=int.Parse(s[1].Substring(0,s[1].Length-1)); | |
if(s[1][s[1].Length-1]=='m')val=int.Parse(s[1].Substring(0,s[1].Length-2)); | |
if(s[0][0]=='角'){ | |
t.Angle[Identifier[s[0]]]=val; | |
} | |
if(s[0][0]!='角'){ | |
t.Edge[Identifier[s[0]]]=val; | |
} | |
} | |
//角度だけは、2つ決まれば3つ目が決まるので決めておく。 | |
int fixedAngle=0; | |
int idx=-1; | |
int sum=0; | |
for(int i=0;i<3;i++){ | |
if(t.Angle[i]>0){ | |
fixedAngle++; | |
sum+=t.Angle[i]; | |
}else{ | |
idx=i; | |
} | |
} | |
if(fixedAngle==2){ | |
t.Angle[idx]=180-sum; | |
} | |
} | |
class Triangle{ | |
//△ABCに対して、時計回りにラべリング | |
// Angle 0 1 2 (0) | |
// A - B - C - (A) | |
// Edge 0 1 2 | |
// | |
public int[] Angle; | |
public int[] Edge; | |
public Triangle(){ | |
// 値が負⇔未確定フラグ。あとで比較するときのために異なる値にしておく | |
Angle=new int[3]{-1,-2,-3}; | |
Edge=new int[3]{-1,-2,-3}; | |
} | |
} | |
String idx; | |
String[] conditions; | |
String ans; | |
public Sol(String[] ss_){ | |
//コンストラクタ:入力データはフィールドで保持。 | |
idx=ss_[0]; | |
conditions=ss_[1].Split(','); | |
ans=ss_[2]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
【解答】 | |
31,41,59,265,358,444,555,666,777,888,979,999 | |
【コード概要】 | |
・入力条件から、三角形の形状を確定していきます。 | |
判定アルゴリズムは | |
1:3つの角が等しい⇒正三角形 | |
2:3つの辺が等しい⇒正三角形 | |
3:(1を満たさず)2つの角が等しい⇒二等辺三角形 | |
4:2つの辺が等しい⇒二等辺三角形または正三角形 | |
正三角形となるのは60度の角が1つ以上確定している時のみ | |
・辺長を正弦/余弦定理等で確定する必要はないですが、角度に関しては2つが決まれば | |
残り一つは決まるので、その場合のみ計算で確定させています。 | |
(形状の判定に辺長の絶対値はそれほど重要ではないですが、 | |
角度は絶対値が決定的なパラメータになるので) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment