- // 小數點處理例
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int x1,y1,x2, y2;
- while (cin >> x1 >> y1 >> x2 >> y2)
- {
- double ans = sqrt((double)(x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
- cout.setf(ios::fixed, ios::floatfield);
- cout.precision(3);
- cout << ans << endl;
- }
- return 0;
- }
標籤雲
2014年6月4日 星期三
2014年5月30日 星期五
//故障計算機
#include <iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
if (n<=9)
cout <<'|' <<"_______" << n <<'|' << endl;
else if (n<=99)
cout <<'|' << "______" << n <<'|' << endl;
else if (n<=999)
cout <<'|' << "_____" << n<<'|' << endl;
else if (n<=9999)
cout <<'|' << "____" << n<<'|' << endl;
else
{
n = n%10000;
if (n<=9)
cout <<'|' <<"____000" << n <<'|' << endl;
else if (n<=99)
cout <<'|' << "____00" << n <<'|' << endl;
else if (n<=999)
cout <<'|' << "____0" << n<<'|' << endl;
else
cout <<"|____" << n<<'|' << endl;
}
}
system("PAUSE");
return 0;
}
// 大數相加、比大小
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a, b;
while (cin >> a >> b)
{
int ar[20], br[20], cr[20],dr[20];
memset(ar, 0, 20 * sizeof(ar[0]));
memset(br, 0, 20 * sizeof(br[0]));
memset(cr, 0, 20 * sizeof(cr[0]));
memset(dr, 0, 20 * sizeof(dr[0]));
int j = 0;
for (int i = a.length() - 1; i >= 0; i--)
{
ar[j] = a[i] - 48;
j++;
}
j = 0;
for (int i = b.length() - 1; i >= 0; i--)
{
br[j] = b[i] - 48;
j++;
}
//subtract
for (int i = 19; i >= 0; i--)
dr[i] = ar[i] - br[i];
for (int i = 0; i <= 18; i++)
if (dr[i] < 0)
{
dr[i + 1] = dr[i + 1] -1;
dr[i] = dr[i] + 10;
}
int i = 19;
while (dr[i] == 0) i--;
if (dr[i] > 0)
cout << "A ";
else if (dr[i] < 0)
cout << "B ";
else
cout << " ";
//plus
for (int i = 19; i >= 0; i--)
cr[i] = br[i] + ar[i];
for (int i = 0; i <= 18; i++)
if (cr[i] >= 10)
{
cr[i + 1] = cr[i + 1] + cr[i] / 10;
cr[i] = cr[i] % 10;
}
i = 19;
while (cr[i] == 0) i--;
while (i >= 0)
{
cout << cr[i];
i--;
}
cout << endl;
}
return 0;
}
2014年4月25日 星期五
Maze Sample
2014年4月22日 星期二
Resurive Sample
'' 求1+3+5+ + 99 = ?
'Public Class Form1
' Dim sumN = 0
' Sub sum(sN, eN, stepN)
' '判斷結束否
' If sN > eN Then Return
' '每次過程要做的事
' sumN = sumN + sN
' '往完成工作方向前進
' sum(sN + stepN, eN, stepN)
' End Sub
' Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Call sum(1, 100, 2)
' MsgBox(sumN)
' End Sub
'End Class
' 求1!+2!+3!+ + 10! = ?
'Public Class Form1
' Dim sumN = 0
' Sub sum(sN, eN, stepN)
' '判斷結束否
' If sN > eN Then Return
' '每次過程要做的事
' Dim tsum = 1
' For i = 1 To sN
' tsum = tsum * i
' Next
' sumN = sumN + tsum
' '往完成工作方向前進
' sum(sN + stepN, eN, stepN)
' End Sub
' Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Call sum(1, 5, 1)
' MsgBox(sumN)
' End Sub
'End Class
'尋找最大值
'Public Class Form1
' Dim maxValue = 0
' Dim a() = {10, 200, 100, 50, 30}
' Sub fMax(sN, eN)
' '判斷結束否
' If sN > eN Then Return
' '每次過程要做的事
' If a(sN) > maxValue Then maxValue = a(sN)
' '往完成工作方向前進
' fMax(sN + 1, eN)
' End Sub
' Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Call fMax(0, a.Length - 1)
' MsgBox(maxValue)
' End Sub
'End Class


