Code: Select all
Code removed.
Moderator: Board moderators
Code: Select all
#include<iostream.h>
#include<string.h>
char digits[10][5][4];
void main(){
strcpy(digits[0][0],"-\0");
strcpy(digits[0][1],"||\0");
strcpy(digits[0][2]," \0");
strcpy(digits[0][3],"||\0");
strcpy(digits[0][4],"-\0");
strcpy(digits[1][0]," \0");
strcpy(digits[1][1]," |\0");
strcpy(digits[1][2]," \0");
strcpy(digits[1][3]," |\0");
strcpy(digits[1][4]," \0");
strcpy(digits[2][0],"-\0");
strcpy(digits[2][1]," |\0");
strcpy(digits[2][2],"-\0");
strcpy(digits[2][3],"| \0");
strcpy(digits[2][4],"-\0");
strcpy(digits[3][0],"-\0");
strcpy(digits[3][1]," |\0");
strcpy(digits[3][2],"-\0");
strcpy(digits[3][3]," |\0");
strcpy(digits[3][4],"-\0");
strcpy(digits[4][0]," \0");
strcpy(digits[4][1],"||\0");
strcpy(digits[4][2],"-\0");
strcpy(digits[4][3]," |\0");
strcpy(digits[4][4]," \0");
strcpy(digits[5][0],"-\0");
strcpy(digits[5][1],"| \0");
strcpy(digits[5][2],"-\0");
strcpy(digits[5][3]," |\0");
strcpy(digits[5][4],"-\0");
strcpy(digits[6][0],"-\0");
strcpy(digits[6][1],"| \0");
strcpy(digits[6][2],"-\0");
strcpy(digits[6][3],"||\0");
strcpy(digits[6][4],"-\0");
strcpy(digits[7][0],"-\0");
strcpy(digits[7][1]," |\0");
strcpy(digits[7][2]," \0");
strcpy(digits[7][3]," |\0");
strcpy(digits[7][4]," \0");
strcpy(digits[8][0],"-\0");
strcpy(digits[8][1],"||\0");
strcpy(digits[8][2],"-\0");
strcpy(digits[8][3],"||\0");
strcpy(digits[8][4],"-\0");
strcpy(digits[9][0],"-\0");
strcpy(digits[9][1],"||\0");
strcpy(digits[9][2],"-\0");
strcpy(digits[9][3]," |\0");
strcpy(digits[9][4],"-\0");
int s,i,k,digi,p;
char str[20];
cin>>s>>str;
while(s!=0 ){
for(i=0;str[i];i++){
digi=str[i]-'0';
cout<<" ";//digits[digi][0][0];
for(k=0;k<s;k++)
cout<<digits[digi][0][0];
cout<<" ";//digits[digi][0][2]<<" ";
}
cout<<endl;
for(k=0;k<s;k++){
for(i=0;str[i];i++){
digi=str[i]-'0';
cout<<digits[digi][1][0];
for(p=0;p<s;p++)
cout<<" ";//digits[digi][1][1];
cout<<digits[digi][1][1]<<" ";
}
cout<<endl;
}
for(i=0;str[i];i++){
digi=str[i]-'0';
cout<<" ";//digits[digi][2][0];
for(k=0;k<s;k++)
cout<<digits[digi][2][0];
cout<<" ";//digits[digi][2][2]<<" ";
}
cout<<endl;
for(k=0;k<s;k++){
for(i=0;str[i];i++){
digi=str[i]-'0';
cout<<digits[digi][3][0];
for(p=0;p<s;p++)
cout<<" ";//digits[digi][3][1];
cout<<digits[digi][3][1]<<" ";
}
cout<<endl;
}
for(i=0;str[i];i++){
digi=str[i]-'0';
cout<<" ";//digits[digi][4][0];
for(k=0;k<s;k++)
cout<<digits[digi][4][0];
cout<<" ";//digits[digi][4][2]<<" ";
}
cout<<endl;
cout<<endl;
cin>>s>>str;
}
}
Not true, this is what my accepted program does. Both these cases should print out a 7.farzane wrote:you should consider leading zeros.
I mean when input is 007 output shouldn't be as same as when input is 7.
I don't understand what you mean here. "0 3" as input should not end the program.farzane wrote: you could get the No in string and for checking end of inputs it is enough just to check s.
I hope it could help.
Code: Select all
/* @BEGIN_OF_SOURCE_CODE */
#include <iostream>
#include <string>
using namespace std;
#define MAX_DIGIT 8
#define MAX_S 10
#define bar1(j, k, s) ( j == 0 && 1 <= k && k <= s )
#define bar2(j, k, s) ( j == s + 1 && 1 <= k && k <= s )
#define bar3(j, k, s) ( j == 2 * s + 2 && 1 <= k && k <= s )
#define bar4(j, k, s) ( 1 <= j && j <= s && k == 0 )
#define bar5(j, k, s) ( s + 2 <= j && j <= 2 * s + 1 && k == 0 )
#define bar6(j, k, s) ( 1 <= j && j <= s && k == s + 1 )
#define bar7(j, k, s) ( s + 2 <= j && j <= 2 * s + 1 && k == s + 1 )
int main()
{
int s;
string n, err_n("0");
cin >> s;
cin.ignore(1, ' ');
getline(cin, n);
while ( s != 0 || n != err_n )
{
int index = n.length();
if ( s <= 0 || s > MAX_S || index > MAX_DIGIT )
{
cin >> s;
cin.ignore(1, ' ');
getline(cin, n);
continue;
}
int i, j, k, k2;
for ( j = 0; j < 2 * s + 3; j++ )
{
for ( i = 0; i < index; i++ )
{
for ( k = (s + 3) * i; k < (s + 3) * (i + 1) - 1; k++ )
{
k2 = k % (s + 3);
switch( n[i] ) {
case '1':
if ( bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '2':
if ( bar1(j, k2, s) || bar2(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar5(j, k2, s) || bar6(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '3':
if ( bar1(j, k2, s) || bar2(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '4':
if ( bar2(j, k2, s) )
cout << "-";
else if ( bar4(j, k2, s) || bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '5':
if ( bar1(j, k2, s) || bar2(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar4(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '6':
if ( bar1(j, k2, s) || bar2(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar4(j, k2, s) || bar5(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '7':
if ( bar1(j, k2, s) )
cout << "-";
else if ( bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '8':
if ( bar1(j, k2, s) || bar2(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar4(j, k2, s) || bar5(j, k2, s) || bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '9':
if ( bar1(j, k2, s) || bar2(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar4(j, k2, s) || bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
case '0':
if ( bar1(j, k2, s) || bar3(j, k2, s) )
cout << "-";
else if ( bar4(j, k2, s) || bar5(j, k2, s) || bar6(j, k2, s) || bar7(j, k2, s) )
cout << "|";
else
cout << " ";
break;
}
}
if ( i != index - 1 )
cout << " ";
}
cout << endl;
}
for ( i = 0; i < (s + 3) * index - 1; i++ )
cout << " ";
cout << endl;
int temp_s = s, temp_index = index;
string temp_n = n;
cin >> s;
cin.ignore(1, ' ');
getline(cin, n);
}
return 0;
}
/* @END_OF_SOURCE_CODE */
Code: Select all
Removed After AC