support bazel complie this project and format code.
This commit is contained in:
23
practical_exercises/10_day_practice/day1/BUILD
Normal file
23
practical_exercises/10_day_practice/day1/BUILD
Normal file
@@ -0,0 +1,23 @@
|
||||
# please run `bazel run //practical_exercises/10_day_practice/day1:union`
|
||||
# please run `bazel run //practical_exercises/10_day_practice/day1:print`
|
||||
# please run `bazel run //practical_exercises/10_day_practice/day1:annotate`
|
||||
# please run `bazel run //practical_exercises/10_day_practice/day1:runnian`
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||
|
||||
cc_binary(
|
||||
name = "union",
|
||||
srcs = ["union.cpp"],
|
||||
)
|
||||
cc_binary(
|
||||
name = "print",
|
||||
srcs = ["print.cpp"],
|
||||
)
|
||||
cc_binary(
|
||||
name = "annotate",
|
||||
srcs = ["annotate.cpp"],
|
||||
)
|
||||
cc_binary(
|
||||
name = "runnian",
|
||||
srcs = ["runnian.cpp"],
|
||||
)
|
||||
@@ -1,8 +1,5 @@
|
||||
#include<iostream>
|
||||
|
||||
|
||||
一种条件编译指令注释
|
||||
|
||||
/* 注释.cpp */
|
||||
#include <iostream>
|
||||
|
||||
//另一种注释方法
|
||||
#if 0
|
||||
@@ -12,5 +9,4 @@ asd
|
||||
//打开注释
|
||||
//条件编译指令
|
||||
#if 1
|
||||
asData
|
||||
#endif
|
||||
24
practical_exercises/10_day_practice/day1/print.cpp
Normal file
24
practical_exercises/10_day_practice/day1/print.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/* 打印练习.cpp */
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main(int argc, char const *argv[]) {
|
||||
int i, j, k, f;
|
||||
for (i = 1; i <= 4; i++) {
|
||||
for (j = 1; j <= 30; j++)
|
||||
cout << " ";
|
||||
for (k = 1; k <= 8 - 2 * i; k++)
|
||||
cout << " ";
|
||||
for (f = 1; f <= 2 * i; f++)
|
||||
cout << '*';
|
||||
cout << endl;
|
||||
}
|
||||
for (i = 1; i <= 3; i++) {
|
||||
for (j = 1; j <= 30; j++)
|
||||
cout << " ";
|
||||
for (f = 1; f <= 7 - 2 * i; f++)
|
||||
cout << '*';
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
17
practical_exercises/10_day_practice/day1/runnian.cpp
Normal file
17
practical_exercises/10_day_practice/day1/runnian.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
/* 是否闰年.cpp */
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
int main(int argc, char const *argv[]) {
|
||||
int year;
|
||||
bool isLeapYear;
|
||||
cout << "Enter the year: ";
|
||||
cin >> year;
|
||||
isLeapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
|
||||
if (isLeapYear) {
|
||||
cout << year << " is a leap year" << endl;
|
||||
} else {
|
||||
cout << year << " is not a leap year" << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
practical_exercises/10_day_practice/day1/union.cpp
Normal file
21
practical_exercises/10_day_practice/day1/union.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/* 联合体学习.cpp */
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
//相同的内存地址
|
||||
union myun {
|
||||
struct {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
} u;
|
||||
int k;
|
||||
} a;
|
||||
int main() {
|
||||
a.u.x = 4;
|
||||
a.u.y = 5;
|
||||
a.u.z = 6;
|
||||
a.k = 0; //覆盖掉第一个int空间值
|
||||
printf("%d %d %d %d\n", a.u.x, a.u.y, a.u.z, a.k);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int i,j,k,f;
|
||||
for (i=1;i<=4;i++){
|
||||
for (j=1;j<=30;j++)
|
||||
cout<<" ";
|
||||
for (k=1;k<=8-2*i;k++)
|
||||
cout<<" ";
|
||||
for (f=1;f<=2*i;f++)
|
||||
cout<<'*';
|
||||
cout<<endl;
|
||||
}
|
||||
for(i=1;i<=3;i++){
|
||||
for (j=1;j<=30;j++)
|
||||
cout<<" ";
|
||||
for (f=1;f<=7-2*i;f++)
|
||||
cout<<'*';
|
||||
cout<<endl;
|
||||
}
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
int main(int argc, char const *argv[])
|
||||
{
|
||||
int year;
|
||||
bool isLeapYear;
|
||||
cout<<"Enter the year: ";
|
||||
cin>>year;
|
||||
isLeapYear = (((year%4==0)&&(year%100!=0))||(year%400==0));
|
||||
if(isLeapYear)
|
||||
{
|
||||
cout<<year<<" is a leap year"<<endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<year<<" is not a leap year"<<endl;
|
||||
}
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
//相同的内存地址
|
||||
union myun
|
||||
{
|
||||
struct { int x; int y; int z; }u;
|
||||
int k;
|
||||
}a;
|
||||
int main()
|
||||
{
|
||||
a.u.x =4;
|
||||
a.u.y =5;
|
||||
a.u.z =6;
|
||||
a.k = 0; //覆盖掉第一个int空间值
|
||||
printf("%d %d %d %d\n",a.u.x,a.u.y,a.u.z,a.k);
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user