一个整数的缩放数字C++程序

编写一个C(或C++)程序来缩放(放大)整数的数字。它应该从用户那里获取一个整数,并使用某种模式以放大的形式显示整数的每个数字。

null

例如:

Input : 123
Output : 

  @
 @@
  @
  @
@@@@@
-------------------------------

@@@@
@  @
  @
 @
@@@@
-------------------------------


@@@@@
    @
@@@@@
    @
@@@@@
-------------------------------

这个创造性的程序从用户那里获取一个整数,然后打印该整数的每个数字 变焦 信息技术

给定的数字首先使用 stringstream 之后,访问每个字符(数字),并将其置于开关盒结构中,开关盒结构将每个数字缩放并以图案的形式打印。

下面是C++实现

// C++ program to zoon digits of an integer
#include <bits/stdc++.h>
using namespace std;
void zoomDigits( int number)
{
// Converting number to string
stringstream ss;
ss << number;
string str = ss.str();
for ( int k=0; k<str.length(); k++)
{
switch (str[k]- '0' )
{
case 0:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (i==0 || i==4)
cout << '@' ;
else if (j==0 || j==4)
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 1:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (j==2)
cout << '@' ;
else if ((i==1 && j==1))
cout << '@' ;
else if (i==4)
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 2:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<4; j++)
{
if (i==0 && j==4)
cout << " " ;
else if (i==0 || i==4)
cout << '@' ;
else if (i==1 && j==0)
cout << '@' ;
else if (i==(4-j))
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 3:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (i==0 || i==2 || i==4)
cout << '@' ;
else if (j==4)
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 4:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (j==4)
cout << '@' ;
else if (i==2)
cout << '@' ;
else if (j==0 && (i==0 || i==1))
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 5:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (i==0 || i==2 || i==4)
cout << '@' ;
else if ((j==0 && i==1) ||
(j==4 && i==3))
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 6:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (i==0 || i==2 || i==4)
cout << '@' ;
else if ((j==0 && (i==1 || i==3)) ||
(j==4 && i==3))
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 7:
for ( int i=0 ; i<5; i++)
{
for ( int j=0 ; j<5; j++)
{
if (i==0 && (j!=4))
cout << '@' ;
else if (i==2 && (j==2 || j==4))
cout << '@' ;
else if (j==3)
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 8:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if (i==0 || i==2 || i==4)
cout << '@' ;
else if ((j==0 && (i==1 || i==3) ||
(j==4 && (i==1 || i==3))))
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
case 9:
for ( int i=0; i<5; i++)
{
for ( int j=0; j<5; j++)
{
if ( i==0 || i==2 || j==4)
cout << '@' ;
else if (i==1 && j==0)
cout << '@' ;
else
cout << " " ;
}
cout << endl;
}
cout << "-------------------------------" ;
continue ;
}
}
}
// Driver code
int main()
{
long long number = 12305;
zoomDigits(number);
return 0;
}


输出:


  @
 @@
  @
  @
@@@@@
-------------------------------

@@@@
@  @
  @
 @
@@@@
-------------------------------

@@@@@
    @
@@@@@
    @
@@@@@
-------------------------------

@@@@@
@   @
@   @
@   @
@@@@@
-------------------------------

@@@@@
@
@@@@@
    @
@@@@@
-------------------------------

本文由 马扎尔·伊玛目·汗 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享