Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // CCC
- //
- // Created by Vlad Russu on 22/03/2019.
- // Copyright © 2019 Vlad Russu. All rights reserved.
- //
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <stdio.h>
- FILE *f = fopen("level2_5.in", "r");
- FILE *g = fopen("level2_5a.out", "w");
- int x,y;
- int wx, wy;
- int steps;
- int orientation;
- int main(int argc, const char * argv[]) {
- if(f == NULL){
- return -1;
- }
- fscanf(f,"%d%d", &wx, &wy);
- fscanf(f,"%d%d", &x, &y);
- char command;
- char s1[1];
- fprintf(g, "%d %d\n", x, y);
- while(fscanf(f,"%s", s1) == 1){
- fscanf(f, "%d", &steps);
- command = s1[0];
- if(command == 'F'){
- switch(orientation){
- case 0:
- // x+=steps;
- for(int i=0;i<steps;i++){
- x++;
- fprintf(g, "%d %d\n", x, y);
- }
- break;
- case 1:
- // y+=steps;
- for(int i=0;i<steps;i++){
- y++;
- fprintf(g, "%d %d\n", x, y);
- }
- break;
- case 2:
- // x-=steps;
- for(int i=0;i<steps;i++){
- x--;
- fprintf(g, "%d %d\n", x, y);
- }
- break;
- case 3:
- // y-=steps;
- for(int i=0;i<steps;i++){
- y--;
- fprintf(g, "%d %d\n", x, y);
- }
- break;
- }
- }
- else{
- orientation = (orientation + steps) % 4;
- }
- }
- // fprintf(g, "%d %d\n", x, y);
- fclose(f);
- fclose(g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement