2016年2月5日 星期五

二信C++寒假練習-zerojudge之 三

// a006. 一元二次方程式
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
   int a, b, c ;
   while( cin >> a >> b >> c )
   {
           int d = b*b - 4*a*c;
      if( d < 0 )
          cout << "No real root\n";
      else if( d == 0 )
          cout << "Two same roots x=" << -b/(2*a) << endl;
      else
          cout << "Two different roots x1=" << (-b + sqrt(d)) / (2*a)
                             << " , x2=" << (-b - sqrt(d)) / (2*a) << endl;
    }
    return 0;
}

//   a009. 解碼器
#include <iostream>
#include <cstring>
using namespace std;
int main( )
{
        string s;
        while( getline(cin,s) )
        {
      int i,n=s.size();
     for(i=0;i<n;i++)
                        cout<<(char (s[i]-7));
                cout<<endl;
        }
   return 0 ;
}

// d126: 一、牧場圍欄   NOI冬令營    計算矩形周長
#include <iostream>
using namespace std;
int main( )
{
   int a,b;
   while( cin >> a >> b)
     cout << a+a+b+b << endl;
   return 0;
}

// d127 牧場面積 -- NOI冬令營    給周長(偶數)計算矩形最大面積
#include <iostream>
using namespace std;
int main( )
{
   long long  l,a,b;
   while( cin >> l)
   {
               l/=2; a=l/2; b=l-a;
           cout <<a*b  << endl;
        }
   return 0;

// d881. 作業苦多
#include <iostream>
using namespace std;
int main( )
{
     int i,d ;
   
    while (cin >>d ) //      cout <<1275+19600*d <<endl ;  //因固定 50 項,可事先求出公式
    {
            int s=1 , a=1 , d2=1; // 1 1,第2項與第1項差為1,第3項與第2項顯差為1+d
            for(i=1; i<50; ++i)
            {
                    a = a+d2; 
                    s = s + a;
                    d2 += d;   // 下一公差 d2
            }
            cout << s << endl;
        }
   
  return 0 ;
}

// d579: 兩條線
#include <iostream>
#include <iomanip>
using namespace std;
int main( )
{
  double n,b;
  while( cin>>n )
  {
     cout << fixed << setprecision(4) << "|"   <<n   << "|=" ;//printf("|%1.4f|=",n);
      if(n<0)n=-n;
     cout << fixed << setprecision(4)  << n << endl ; // printf("%1.4f\n",n);
  }
    return 0 ;
}

//   d581. 三條線    輸入 t , 印出 t 列的 =_=|||
#include <iostream>
using namespace std;
int main( )
{
   int t ;
   while(cin >> t)
     while(t--)
             cout << "=_=|||" << endl;
   return 0;
}

//   d532. 文文的求婚 () -- 板橋高中教學題
#include<iostream>
using namespace std;

bool isleap(int y)
{
  if( (y%4==0 && y%100 ) || (y%400==0) ) return true;
  else return false;
}

int main()
{
 int a,b,y,cnt;
 while(cin>>a>>b)
 {
    cnt=0;
    while(!isleap(a)) a++;
    for(y=a;y<=b;y+=4)
    {
      if(isleap(y)) cnt++;
    }
    cout<<cnt<<endl;
 }
  return 0;
}

//   d559. 班號
#include <iostream>
using namespace std;
string s="'C' can use printf(\"%d\",n); to show integer like ";
int main()
{
   int n;
    while ( cin>>n)
    {
       cout<<s<<n<<endl;
    }
       
    return 0;
}




0 意見:

張貼留言