Moderator: Board moderators
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char grafica[120][70]={"\0"};
int tops[120]={0};
char cadena[53]={"\0"},limpia[60]={"\0"},ant='\0';
int n,s,x,y,i,j,topx,topy,tope,boty;
for (i=0;i<120;i++)
{
for (j=0;j<70;j++)
grafica[i][j]=' ';
tops[i]=0;
}
cin >>n;
cin.getline(cadena,0);
s=1;
while (n--)
{
cin.getline(cadena,52);
x=2;
y=58;
topx=2;
topy=58;
boty=58;
tope=strlen(cadena);
ant='\0';
for (i=0;i<tope;i++)
{
if (cadena[i]=='R')
{
if (ant==92)
{
y--;
grafica[y][x]='/';
topy=(y<topy)?y:topy;
boty=(y>boty)?y:boty;
tops[y]=(x>tops[y])?x:tops[y];
x++;
y--;
topx=x;
}
else
{
topy=(y<topy)?y:topy;
boty=(y>boty)?y:boty;
grafica[y][x]='/';
tops[y]=(x>tops[y])?x:tops[y];
x++;
y--;
topx=x;
}
ant='/';
}
else
if (cadena[i]=='C')
{
if (ant==92)
{
y--;
grafica[y][x]='_';
tops[y]=(x>tops[y])?x:tops[y];
boty=(y>boty)?y:boty;
x++;
topx=x;
ant='_';
topy=(y<topy)?y:topy;
}
else
{
grafica[y][x]='_';
tops[y]=(x>tops[y])?x:tops[y];
topy=(y<topy)?y:topy;
x++;
topx=x;
}
ant='_';
}
else
if (cadena[i]=='F')
{
if (ant=='/' || ant=='_')
{
y++;
grafica[y][x]=92;
tops[y]=(x>tops[y])?x:tops[y];
boty=(y>boty)?y:boty;
x++;
y++;
topx=x;
}
else
{
grafica[y][x]=92;
tops[y]=(x>tops[y])?x:tops[y];
boty=(y>boty)?y:boty;
x++;
y++;
topx=x;
}
topy=(y<topy)?y:topy;
ant=92;
}
}
cout <<"Case #"<<s<<":"<<endl;
s++;
boty++;
for (i=topy;i<boty;i++)
{
cout <<"| ";
for (j=2;j<=tops[i];j++)
{
cout<<grafica[i][j];
}
cout<<endl;
}
cout<<"+";
for (i=0;i<topx;i++)
cout <<"-";
cout <<endl;
cout<<endl;
for (i=0;i<120;i++)
{
for (j=0;j<70;j++)
grafica[i][j]=' ';
tops[i]=0;
}
strcpy(cadena,"\0");
}
return 0;
}
18
F
C
R
FF
CC
RR
RF
FR
FCR
RCF
CFF
FCF
FFC
CRR
RCR
RRC
FRFR
RFRFCase #1:
| \
+---
Case #2:
| _
+---
Case #3:
| /
+---
Case #4:
| \
| \
+----
Case #5:
| __
+----
Case #6:
| /
| /
+----
Case #7:
| /\
+----
Case #8:
| \/
+----
Case #9:
| \_/
+-----
Case #10:
| _
| / \
+-----
Case #11:
| _
| \
| \
+-----
Case #12:
| \_
| \
+-----
Case #13:
| \
| \_
+-----
Case #14:
| /
| _/
+-----
Case #15:
| _/
| /
+-----
Case #16:
| _
| /
| /
+-----
Case #17:
| \/\/
+------
Case #18:
| /\/\
+------
1
CCCFFFRFFF
Case #1:
| ___
| \
| \
| \/\
| \
| \
+------------
n00i3 wrote:guys
i was wondering if this was legal :S
- Code: Select all
1
CCCFFFRFFF
Case #1:
| ___
| \
| \
| \/\
| \
| \
+------------

#include <stdio.h>
#include <string.h>
#define max 120
char m[max][max],s[max];
void init(){
int i,j;
for(i=0;i<=110;i++)
for(j=0;j<=110;j++)
m[i][j]=' ';
for(i=0;i<=110;i++)m[i][0]='|';
}
void unnes(){
int i,j;
for(i=110;i>=0;i--){
for(j=110;j>=0;j--){
if(m[i][j]==' ')m[i][j]=NULL;
else break;
}
}
}
int main(){
int n,cases=1,l,i,j;
int r,c,m_r,h_r;
scanf("%d",&n);
gets(s);
for(;n>0;n--){
init();
gets(s);
l=strlen(s);
printf("Case #%d:\n",cases++);
r=55,c=2;
m_r=h_r=r;
for(i=0;i<l;i++){
if(s[i]=='R'){
m[r][c++]='/';
r--;
if(r<h_r)h_r=r;
}
else if (s[i]=='F'){
m[++r][c++]=92;
if(r>m_r)m_r=r;
}
else if(s[i]=='C')
m[r][c++]='_';
}
m_r++;
for(i=0;i<=c;i++)
m[m_r][i]='-';
unnes();
m[m_r][0]='+';
for(i=h_r;i<=m_r;i++){
if(strlen(m[i])==1)continue;
for(j=0;j<=c;j++)
printf("%c",m[i][j]);
printf("\n");
}
printf("\n");
}
return 0;
}
Case #1:
| /\
| / \
| \
| \
+--------
Case #2:
| ____
| \
| \
| \
| \
+----------
Case #3:
| /
| /
| /
| _/
+-------
Case #4:
| \ _
| \ /
| \/
+--------
Case #5:
| \
| \___/
+--------
#include<algorithm>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define sz size()
#define pb push_back
#define all(a) a.begin(),a.end()
typedef vector<int> vi;
typedef vector<string> vs;
int main()
{
int n;
cin>>n;
for(int p=1;p<=n;p++)
{
string str="";int a[400][400];
memset(a,0,sizeof(a));
cin>>str;int j=200,k=1;
cout<<"Case #"<<p<<":";
for(int i=0;i<str.sz;i++)
{
if(str[i]=='C')
{
if(i==0)
{
a[j][k]=1;
continue;
}
if(str[i-1]=='R')
{
--j;++k;
a[j][k]=1;
continue;
}
if(str[i-1]=='F')
{
++k;
a[j][k]=1;
continue;
}
if(str[i-1]=='C')
{
++k;
a[j][k]=1;
continue;
}
}
if(str[i]=='R')
{
if(i==0)
{
a[j][k]=2;
continue;
}
if(str[i-1]=='C')
{
++k;
a[j][k]=2;
continue;
}
if(str[i-1]=='F')
{
++k;
a[j][k]=2;
continue;
}
if(str[i-1]=='R')
{
--j;++k;
a[j][k]=2;
continue;
}
}
if(str[i]=='F')
{
if(i==0)
{
a[j][k]=3;
continue;
}
if(str[i-1]=='R')
{
++k;
a[j][k]=3;
continue;
}
if(str[i-1]=='F')
{
++j;++k;
a[j][k]=3;
continue;
}
if(str[i-1]=='C')
{
++j;++k;
a[j][k]=3;
continue;
}
}
}
bool f1=false;
for(int i=0;i<400;i++)
{
bool f2=false;
for(j=0;j<=k;j++)
{
if(f1==false)
if(a[i][j]==1||a[i][j]==2||a[i][j]==3)
{
f1=true;
f2=true;
i=i-1;
//cout<<"|";
break;
}
if(f1)
{
if(a[i][j]==1)
{
cout<<"_";
f2=true;
continue;
}
if(a[i][j]==2)
{
cout<<"/";
f2=true;
continue;
}
if(a[i][j]==3)
{
cout<<"\\";
f2=true;
continue;
}
cout<<" ";
}
}
if(f1&&f2)
{
cout<<endl;
cout<<"|";
}
if(f2==false&&f1==true)
{
for(int r=0;r<=k+1;r++)
cout<<"\b";
cout<<"+";
for(int l=1;l<=k+2;l++)
cout<<"-";
cout<<"\n";
break;
}
}
cout<<"\n";
}
return 0;
}Users browsing this forum: No registered users and 0 guests