Holey_yan

20150312_KUAS_VisualC++_Exam02

Mar 12th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. /***************************************/
  2. /** 20150312 Exam 02                  **/
  3. /** Maker  : Yan                      **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2015/03/12 am.11:45      **/
  6. /***************************************/
  7.  
  8. #include <iostream> //Basic C++ I/O stream
  9. #include <vector>
  10.  
  11. using namespace std;
  12. int main(int argc, char const argv[]){
  13.     int nData = 0;
  14.     cin >> nData;
  15.  
  16.     /* Make a vector with integer type. Have 100 element, and set the value be [-1]
  17.        If just want to make a vector:
  18.        vector <type> [VectorName](Number of Element);
  19.  
  20.        Or your want to set the value to vector at first:
  21.        vector <type> [VectorName](Number of Element, Value); */
  22.     vector <int> ivector(100, -1);
  23.     for(int i = 0; i < nData; i++){
  24.         cin >> ivector[i * 1 + 1];
  25.         cin >> ivector[i * 2 + 1];
  26.  
  27.         cout << "Your number:\n\t" << \
  28.             "A = " << ivector[i * 1 + 1] << ", " << "B = " << ivector[i * 2 + 1] << endl;
  29.  
  30.         if(ivector[i * 1 + 1] == ivector[i * 2 + 1])
  31.             cout << "G.C.D. is " << ivector[i * 1 + 1] << "." << endl << endl;
  32.         else
  33.             for(int j = ((ivector[i * 1 + 1] > ivector[i * 2 + 1]) ? ivector[i * 2 + 1] : ivector[i * 1 + 1]); j > 0; j--)
  34.                 if((ivector[i * 1 + 1] % j == 0) && (ivector[i * 2 + 1] % j == 0)){
  35.                     //Greatest Common Divisor(G.C.D.)
  36.                     cout << "G.C.D. is " << j << "." << endl << endl;
  37.                     break;
  38.                 }
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment