Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- My actual solutions to CCC Junior 2012
- Dev-C++ was the IDE used, and its quirks
- led to some things that I would have preferred
- not doing (e.g. cout in a function instead of returning
- the value to be printed in the main function)
- */
- // CCC 2012 Problem J1
- #include <iostream>
- using namespace std;
- int speedDiff(int speedlim, int speed){
- int diff = speed - speedlim;
- return diff;
- }
- int main(){
- int speed;
- int speedlim;
- cout << "Enter the speed limit: ";
- cin >> speedlim;
- cout << "Enter the recorded speed of the car: ";
- cin >> speed;
- int pay = speedDiff(speedlim, speed);
- if(pay <= 0){
- cout << "Congratulations, you are within the speed limit!" << endl;
- }
- else if(pay >= 31){
- cout << "You are speeding and your fine is $500" << endl;
- }
- else{
- cout << "You are speeding and your fine is $100" << endl;
- }
- return 0;
- }
- // Problem J2
- #include <iostream>
- using namespace std;
- int main(){
- int depth1,depth2,depth3,depth4;
- cin >> depth1;
- cin >> depth2;
- cin >> depth3;
- cin >> depth4;
- if(depth1 < depth2 && depth2 < depth3 && depth3 < depth4){
- cout << "Fish Rising" << endl;
- }
- else if(depth1 > depth2 && depth2 > depth3 && depth3 > depth4){
- cout << "Fish Diving" << endl;
- }
- else{
- cout << "No Fish" << endl;
- }
- return 0;
- }
- // Problem J3
- #include <iostream>
- using namespace std;
- int main(){
- int scale;
- cin >> scale;
- for(int i = 0; i < scale; i++){
- for(int i = 0; i < scale; i++){
- cout << "*";
- }
- for(int i = 0; i < scale; i++){
- cout << "X";
- }
- for(int i = 0; i < scale; i++){
- cout << "*";
- }
- cout << endl;
- }
- for(int i = 0; i < scale; i++){
- for(int i = 0; i < scale; i++){
- cout << " ";
- }
- for(int i = 0; i < scale; i++){
- cout << "X";
- }
- for(int i = 0; i < scale; i++){
- cout << "X";
- }
- cout << endl;
- }
- for(int i = 0; i < scale; i++){
- for(int i = 0; i < scale; i++){
- cout << "*";
- }
- for(int i = 0; i < scale; i++){
- cout << " ";
- }
- for(int i = 0; i < scale; i++){
- cout << "*";
- }
- cout << endl;
- }
- return 0;
- }
- // Problem J4
- #include <iostream>
- #include <vector>
- using namespace std;
- void shiftInput(int shift, string input){
- vector<char> ss;
- string output;
- int rShift;
- int currChar;
- int nextChar;
- char nextCh;
- for(int i = 0; i < input.size(); i++){
- rShift = 3 * (i+1) + shift;
- char aChar = input[i];
- currChar = (int) aChar;
- nextChar = currChar - rShift;
- while(nextChar < 65){
- nextChar += 26;
- }
- nextCh = (char) nextChar;
- cout << nextCh;
- }
- cout << endl;
- }
- int main(){
- int shift;
- string input;
- cin >> shift;
- cin >> input;
- shiftInput(shift, input);
- return 0;
- }
- // Problem J5: No solution found. Only theoretical solution considered is very complicated
- // and was not implemented in the time frame of the contest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement