CPSC 602 / Section 600

Dr. Salih Yurttas - March 5, 2008

Test 1


  1. (100 points)
    
    // a_01.cpp
    
    #include <iostream>
    #include <vector>
    #include <string>
    
    using namespace std;
    
    const string B = "10";
    
    int main(int argc, char* argv[]) {
      // init
      vector<string> given;
    
      given.push_back("01010101");
      given.push_back("11000011");
      given.push_back("10011000");
      given.push_back("10010111");
    
      // compute
      vector< vector<int> > computed;
    
      int n = given.size();
    
      for(int i=0; i<n; ++i) {
        string t = given.at(i);
    
        // count
        vector<int> counts(2,0);
        char b = B.at(0);
    
        int l = t.length();
        for(int j=0; j<l; ++j)
          if(t.at(j)==b) ++counts.at(0);
          else ++counts.at(1);
        computed.push_back(counts);
      }
    
      // output
      int m = computed.size();
    
      cout << endl;
    
      for(int i=0; i<m; ++i) {
        vector<int> v = computed.at(i);
        cout << v.at(0) << endl;
      }
    
      cout << endl;
    
      // output
      for(int i=0; i<m; ++i) {
        vector<int> v = computed.at(i);
        cout << v.at(1) << endl;
      }
    }
    
    
    
    
    4
    4
    3
    5
    
    4
    4
    5
    3