Advertisement
kylemsguy

CCC 2012 Solutions

Mar 1st, 2012
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.48 KB | None | 0 0
  1. /*
  2.   My actual solutions to CCC Junior 2012
  3.   Dev-C++ was the IDE used, and its quirks
  4.   led to some things that I would have preferred
  5.   not doing (e.g. cout in a function instead of returning
  6.   the value to be printed in the main function)
  7. */
  8.  
  9. // CCC 2012 Problem J1
  10. #include <iostream>
  11. using namespace std;
  12.  
  13. int speedDiff(int speedlim, int speed){
  14.     int diff = speed - speedlim;
  15.     return diff;
  16.  
  17. }
  18.    
  19.  
  20. int main(){
  21.     int speed;
  22.     int speedlim;
  23.     cout << "Enter the speed limit: ";
  24.     cin >> speedlim;
  25.     cout << "Enter the recorded speed of the car: ";
  26.     cin >> speed;
  27.    
  28.     int pay = speedDiff(speedlim, speed);
  29.     if(pay <= 0){
  30.            cout << "Congratulations, you are within the speed limit!" << endl;
  31.     }
  32.     else if(pay >= 31){
  33.          cout << "You are speeding and your fine is $500" << endl;
  34.     }
  35.     else{
  36.          cout << "You are speeding and your fine is $100" << endl;
  37.     }
  38.  
  39.     return 0;
  40. }
  41.    
  42.  
  43. // Problem J2
  44. #include <iostream>
  45. using namespace std;
  46.  
  47. int main(){
  48.     int depth1,depth2,depth3,depth4;
  49.     cin >> depth1;
  50.     cin >> depth2;
  51.     cin >> depth3;
  52.     cin >> depth4;
  53.    
  54.     if(depth1 < depth2 && depth2 < depth3 && depth3 < depth4){
  55.               cout << "Fish Rising" << endl;
  56.     }
  57.     else if(depth1 > depth2 && depth2 > depth3 && depth3 > depth4){
  58.          cout << "Fish Diving" << endl;
  59.     }
  60.     else{
  61.          cout << "No Fish" << endl;
  62.     }
  63.    
  64.     return 0;
  65. }
  66.  
  67.  
  68. // Problem J3
  69. #include <iostream>
  70. using namespace std;
  71.  
  72. int main(){
  73.     int scale;
  74.     cin >> scale;
  75.     for(int i = 0; i < scale; i++){
  76.         for(int i = 0; i < scale; i++){
  77.                 cout << "*";
  78.         }
  79.         for(int i = 0; i < scale; i++){
  80.                 cout << "X";
  81.         }
  82.         for(int i = 0; i < scale; i++){
  83.                 cout << "*";
  84.         }
  85.         cout << endl;
  86.     }
  87.     for(int i = 0; i < scale; i++){
  88.         for(int i = 0; i < scale; i++){
  89.                 cout << " ";
  90.         }
  91.         for(int i = 0; i < scale; i++){
  92.                 cout << "X";
  93.         }
  94.         for(int i = 0; i < scale; i++){
  95.                 cout << "X";
  96.         }
  97.         cout << endl;
  98.     }
  99.     for(int i = 0; i < scale; i++){
  100.         for(int i = 0; i < scale; i++){
  101.                 cout << "*";
  102.         }
  103.         for(int i = 0; i < scale; i++){
  104.                 cout << " ";
  105.         }
  106.         for(int i = 0; i < scale; i++){
  107.                 cout << "*";
  108.         }
  109.         cout << endl;
  110.     }
  111.     return 0;
  112. }
  113.  
  114.  
  115. // Problem J4
  116. #include <iostream>
  117. #include <vector>
  118. using namespace std;
  119.  
  120. void shiftInput(int shift, string input){
  121.        vector<char> ss;
  122.        string output;
  123.        int rShift;
  124.        int currChar;
  125.        int nextChar;
  126.        char nextCh;
  127.        for(int i = 0; i < input.size(); i++){
  128.                rShift = 3 * (i+1) + shift;
  129.                char aChar = input[i];
  130.                currChar = (int) aChar;
  131.                nextChar = currChar - rShift;
  132.                while(nextChar < 65){
  133.                               nextChar += 26;
  134.                }
  135.                nextCh = (char) nextChar;
  136.                cout << nextCh;
  137.        }
  138.        cout << endl;
  139.        
  140. }
  141. int main(){
  142.     int shift;
  143.     string input;
  144.    
  145.     cin >> shift;
  146.     cin >> input;
  147.    
  148.     shiftInput(shift, input);
  149.     return 0;
  150.    
  151. }
  152.  
  153. // Problem J5: No solution found. Only theoretical solution considered is very complicated
  154. // and was not implemented in the time frame of the contest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement