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;
}