2018年4月27日 星期五

P1 TAB 小考1範例


P1(TAB) 小考1範例

程式1      (1) 1   __1912__
int y;       (2)100  _2011__
cin >> y; 
cout << y+1911 << endl; 
程式2      (1) 5 2  __10__
int h , w ;    (2) 3 4  __12__
cin >> h >> w; 
cout << h*w << endl; 
程式3      (1) 1 2  __62__
int h,m;     (2) 3 4  __184__
cin >> h >> m; 
cout << h * 60 + m << endl;
程式4   (1) 2   __P1x__
int n;     __P1x__
cin >> n;
int i;
for( i=1; i<=n; ++i )
{
   cout << "P1x" << endl;
} 
程式5      (1) 55   __F__
 int sco;     (2) 66   __P__
 cin >> sco; 
  if ( sco<60 )
     cout <<"F\n";
  else
     cout << "P" << endl;
程式6     (1) 1   __D__
int n ;      (2) 2   __V__
  cin >> n; 
  if ( n%2 == 1 )
      cout <<"D\n"; 
  else   
      cout << "V\n";
程式7      (1) 2500   __L__
int y;       (2) 2100   __N__
  cin >> y; 
  if( y%250==0 || ( y%4==0 && y%100 != 0 ) ) 
       cout <<"L\n"; 
else cout <<"N\n";
程式8         (1) 16 10   __N__
int t, h,m;       (2) 13 20   __Y__
 cin >> h >> m; 
 t = h*60 + m;
 if( t >= 800 && t <= 960 )    cout << "Y\n"; 
 else   cout <<"N\n";   
程式9      (1) 24   __3__
  int n; 
   cin >> n;  
   while( n%2==0 )
   { 
        n /= 2;  
   } 
   cout << n << endl; 
程式10     (1) 2100   __3__
  int n ,m , cnt=0; 
    cin >> n >> m; 
   while( n<m ) 
   { 
      ++cnt; 
      n*=3; 
   } 
   cout << cnt << endl; 
程式11    (1) 5   __6__
   int n ,m, cnt=1 ; 
    cin >> n ; 
   while( n>1 ) 
   { 
      ++cnt; 
      if( n%2==0 ) n /= 2; 
      else n = n*3 + 1; 
   } 
   cout << cnt << endl; 
程式12    (1) 543   __345__
int n;
cin >> n;
int sum = 0;
while( n != 0 )
{
  sum = sum * 10 + ( n%10 );
  n /= 10; 
}
cout << sum << endl;
程式13    (1) 2 4   __0__
int a,b , tot=0; 
  cin >> a >> b; 
  if( b%3==2 ) tot += 200;
  if( a%2 ) tot += 100;
  if( a==b )  tot += 50;
  cout << tot << endl;
程式14    (1) 3   __3 2 1 0__
int i,n;
cin >> n ;
for (  i=n; i>=0  ; --i  )
{
   cout << i << " ";
}
cout << endl; 


0 意見:

張貼留言