Posted: Thu Apr 10, 2003 4:35 am
Hi,
No Trick at all. Just do what they want.
No Trick at all. Just do what they want.
Code: Select all
#include <iostream.h>
#include <string.h>
#include <stdio.h>
void main() {
int i,j,g,p,x,y;
char a[200],niz[35][35];
cin >> g;
for (p=0;p<g;p++) {
cin >> x >> y;
y = 31 - y; // so y would be down in the graph...
for (i=0;i<32;i++)
for (j=0;j<32;j++) niz[i][j]='.';
gets(a);
for (j=0;j<(signed)strlen(a)-1;j++) {
if (a[j]=='E') {
niz[y+1][x]='X';
if (a[j+1]=='E') x++;
if (a[j+1]=='S') {y++; x++;}
}
if (a[j]=='N') {
niz[y][x+1]='X';
if (a[j+1]=='N') y--;
if (a[j+1]=='E') {y--; x++;}
}
if (a[j]=='W') {
niz[y-1][x]='X';
if (a[j+1]=='W') x--;
if (a[j+1]=='N') {y--; x--;}
}
if (a[j]=='S') {
niz[y][x-1]='X';
if (a[j+1]=='S') y++;
if (a[j+1]=='W') {y++; x--;}
}
} // end for j
// write out the graph..
cout << "Bitmap #" << p+1 << endl;
// ispis
for (i=0;i<32;i++) {
for (j=0;j<32;j++) cout << niz[i][j];
cout << endl;
}
cout << endl;
} // end for p
}
Code: Select all
3
2 1
EEENNNWWWSSS.
2 1
ENWS.
2 1
EEEEEEEEEENWWWWWWWWWWS.
Code: Select all
Bitmap #1
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
..XXX...........................
.X...X..........................
.X...X..........................
.X...X..........................
..XXX...........................
Bitmap #2
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
..X.............................
.X.X............................
..X.............................
Bitmap #3
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
..XXXXXXXXXX....................
.X..........X...................
..XXXXXXXXXX....................
Code: Select all
int main()
{
int cases;
cin>>cases;
for(int casei=1;casei<=cases;casei++)
{
bool bitmap[32][32];
for(int i=0;i<32;i++)
for(int j=0;j<32;j++)
bitmap[i][j]=false;
int x,y;
cin>>x>>y;
string line;
getline(cin,line);
if(line=="")
getline(cin,line);
for(int i=0;i<(int)line.size()-1;i++)
{
if(line[i]=='E')
etc....
}
cout<<"Bitmap #"<<casei<<endl;
output....
}
return 0;
}
Code: Select all
#include <iostream>
#include <string>
using namespace std;
#define MAX 32
char result[MAX][MAX];
int pre_c = -1;
int x, y;
void init() {
for(int i = 0 ; i < MAX ; i++) {
for(int j = 0 ; j < MAX ; j++) {
result[i][j] = '.';
}
}
pre_c = -1;
}
void func(int c) {
switch(c) {
case 0:
if(pre_c == c) {
x--;
} else if(pre_c == 3) {
x--;
y--;
}
result[y + 1][x] = 'X';
break;
case 1:
if(pre_c == c) {
x++;
} else if(pre_c == 2) {
x++;
y++;
}
result[y - 1][x] = 'X';
break;
case 2:
if(pre_c == c) {
y++;
} else if(pre_c == 0) {
x--;
y++;
}
result[y][x + 1] = 'X';
break;
case 3:
if(pre_c == c) {
y--;
} else if(pre_c == 1) {
x++;
y--;
}
result[y][x - 1] = 'X';
break;
}
pre_c = c;
}
void dump(int counter) {
cout << "Bitmap #" << counter << endl;
for(int i = MAX - 1 ; i >= 0 ; i--) {
for(int j = 0 ; j < MAX ; j++) {
cout << result[i][j];
}
cout << endl;
}
cout << endl;
}
int main() {
int n;
char c;
int counter = 1;
string ss;
cin >> n;
while(n--) {
cin >> x >> y;
init();
cin >> ss;
int i = 0;
while(true) {
c = ss[i++];
if(c == '.') {
dump(counter);
counter++;
break;
}
switch(c) {
case 'W':
func(0);
break;
case 'E':
func(1);
break;
case 'N':
func(2);
break;
case 'S':
func(3);
break;
}
}
}
return 0;
}
Code: Select all
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void main() {
int i,j,g,p,x,y;
char niz[35][35],a[200];
cin >> g;
for (p=0;p<g;p++) {
cin >> x >> y;
y = 31 - y; // this is so i could work with Y on the bottom of
// the graph. so i don't invert the graph.
for (i=0;i<32;i++) // init grafika
for (j=0;j<32;j++) niz[i][j]='.';
//gets(a);
// my NEW input...
cin.getline( a, 200);
if(strlen(a)==0) cin.getline( a, 200);
for (j=0;j<(signed)strlen(a)-1;j++) {
if (a[j]=='E') {
niz[y+1][x]='X';
if (a[j+1]=='E') x++;
if (a[j+1]=='S') {y++; x++;}
}
if (a[j]=='N') {
niz[y][x+1]='X';
if (a[j+1]=='N') y--;
if (a[j+1]=='E') {y--; x++;}
}
if (a[j]=='W') {
niz[y-1][x]='X';
if (a[j+1]=='W') x--;
if (a[j+1]=='N') {y--; x--;}
}
if (a[j]=='S') {
niz[y][x-1]='X';
if (a[j+1]=='S') y++;
if (a[j+1]=='W') {y++; x--;}
}
} // end for j
cout << "Bitmap #" << p+1 << endl;
// output
for (i=0;i<32;i++) {
for (j=0;j<32;j++) cout << niz[i][j];
cout << endl;
}
cout << endl;
} // end for p
}
Code: Select all
1
3 6
SSSEEENNNWWW.
Code: Select all
Bitmap #1
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
................................
...XXX..........................
..X...X.........................
..X...X.........................
..X...X.........................
...XXX..........................
................................
................................
Code: Select all
for (j=0;j<(signed)strlen(a)-1;j++) {....}
Code: Select all
#include <iostream> //for cin and cout and streams etc...
#include <string> //for C++ class std::string
#include <cstdio> //for C style printf and scanf
#include <cstdlib> //for C style utility functions
#include <cstring> //for C style string functions such as strlen
using namespace std;//so you don't have to put std:: in front of everything
Code: Select all
string line;
getline(cin,line);