(上图,向左滑动)
下面才是准备的礼物,使用编程语言打印出爱心:
刺不刺激,惊不惊喜,意不意外
Java:
// Java code to print a HEART Shape
class Heart{
public static void main(String arg[]) {
// size = 10
int a, b, size = 15;
/* FOR THE APEX OF HEART */
for (a = size / 2; a <= size; a = a + 2) {
for (b = 1; b < size - a; b = b + 2)
System.out.print(" ");
for (b = 1; b <= a; b++)
System.out.print("A");
for (b = 1; b <= size - a; b++)
System.out.print(" ");
for (b = 1; b <= a - 1; b++)
System.out.print("A");
System.out.print("\n");
}
/*THE INVERTED TRIANGLE */
for (a = size; a >= 0; a--) {
// THE INVERTED TRIANGLE
for (b = a; b < size; b++)
System.out.print(" ");
// THE BASE OF TRIANGLE
for (b = 1; b <= ((a * 2) - 1); b++)
System.out.print("V");
System.out.print("\n");
}
}
}
C++:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
double x, y,
size=10;
char ch=3;
string message(" Happy Valentine's Day ");
int print_line = 4;
if(message.length() % 2 != 0)
message += " ";
for(x=0;x<size;x++)
{
for(y=0;y<=4*size;y++)
{
double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );
if (dist1 < size + 0.5 || dist2 < size + 0.5 ) {
cout<< ch;
}
else
cout<< " ";
}
cout<<"\n";
}
for(x=1;x<2*size;x++)
{
for(y=0;y<x;y++)
cout << " ";
for (y=0;y<4*size + 1 - 2*x; y++)
{
if (x>= print_line - 1 && x <= print_line + 1) {
int idx = y - (4*size - 2*x - message.length()) / 2;
if(idx < message.length() && idx >= 0) {
if (x == print_line)
cout<<message[idx];
else cout << " ";
}
else
cout << ch;
}
else
cout<< ch;
}
cout<<endl;
}
return 0;
}
HTML+CSS:
<div class="heart"></div>
.heart {
background-color: red;
display: inline-block;
height: 30px;
margin: 0 10px;
position: relative;
top: 0;
transform: rotate(-45deg);
width: 30px;
}
.heart:before,
.heart:after {
content: "";
background-color: red;
border-radius: 50%;
height: 30px;
position: absolute;
width: 30px;
}
.heart:before {
top: -15px;
left: 0;
}
.heart:after {
left: 15px;
top: 0;
}
Python3:
print('\n'.join([''.join([('LoveDaLin'[(x-y)%8]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for x in range(-30,30)])for y in range(15,-15,-1)]))
目前5000+人已关注加入我们