1.1编程基础之输入输出
Portal:http://noi.openjudge.cn/ch0101/
这套题里有⑨道水题,一道sb题(第十题)
不过就算这样也是题,总结一下心得
///
首先是c++STL里的cout/cin(属于iostream库)
cout<<...<<...<..<<endl;
cin>>...>>...>..>;
///
然后想到了读入字符串用的getline(属于iostream库)
打一下格式防止忘记
getline(cin,变量);
为什么不用cin来做呢?这是因为有人会卡cin读入的时间/sad
然后偶然发现getline可以这么用:
getline(cin,变量,标示符);//读取直到表示符为止的整行文本(默认是\n?)
///
然后就是scanf/printf了(属于cstdilb库)
...好烦的
scanf(格式,地址);/printf(格式,地址);
格式=[输出最小宽度][精度][长度][类型]
格式总结(当然不全):
精度
.+数字
长度:
h 按短整型量输出
l 按长整型量输出
类型:
%d 十进制整数
%i 十/八/十六进制整数
%o 八进制整数
%x 十六进制整数
%c 字符
%s 字符串
%f 浮点数
如scanf/printf("%3.4lf\n", a);
///
下面贴上代码
代码风格渣,不要吐槽
01
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<algorithm> 3 #include<set> 4 using namespace std; 5 #define FOR(i,j,k) for(int i=j;i<=k;i++) 6 #define FORD(i,j,k) for(int i=j;i>=k;i--) 7 int main() 8 { 9 cout<<"Hello, World!"; 10 return 0; 11 }
02
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a,b,c; cin>>a>>b>>c; cout<<b; return 0; }
03
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { int a,b,c; cin>>a>>b>>c; printf("%8d %8d %8d",a,b,c); return 0; }
04
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { float a; cin>>a; printf("%.3f",a); return 0; }
05
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { double a; cin>>a; printf("%.12f",a); return 0; }
06
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { char a; int b; float c; double d; cin>>a>>b>>c>>d; printf("%c %d %.6f %.6f",a,b,c,d); return 0; }
07
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> #include<cstdio> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { double a; cin>>a; printf("%f\n",a); printf("%.5f\n",a); printf("%e\n",a); printf("%g\n",a); return 0; }
08
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { char a; cin>>a; FOR(i,1,3) { FOR(j,1,3-i) cout<<' '; FOR(j,1,2*i-1) cout<<a; FOR(j,1,3-i) cout<<' '; cout<<endl; } return 0; }
09
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { char a; cin>>a; FOR(i,1,3) { FOR(j,1,3-i) cout<<' '; FOR(j,1,2*i-1) cout<<a; FOR(j,1,3-i) cout<<' '; cout<<endl; } FORD(i,2,1) { FOR(j,1,3-i) cout<<' '; FOR(j,1,2*i-1) cout<<a; FOR(j,1,3-i) cout<<' '; cout<<endl; } return 0; }
10
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<algorithm> #include<set> using namespace std; #define FOR(i,j,k) for(int i=j;i<=k;i++) #define FORD(i,j,k) for(int i=j;i>=k;i--) int main() { cout<<" ********"<<endl; cout<<" ************"<<endl; cout<<" ####....#."<<endl; cout<<" #..###.....##...."<<endl; cout<<" ###.......###### ### ### ### ###"<<endl; cout<<" ........... #...# #...# #...# #...#"<<endl; cout<<" ##*####### #.#.# #.#.# #.#.# #.#.#"<<endl; cout<<" ####*******###### #.#.# #.#.# #.#.# #.#.#"<<endl; cout<<" ...#***.****.*###.... #...# #...# #...# #...#"<<endl; cout<<" ....**********##..... ### ### ### ###"<<endl; cout<<" ....**** *****...."<<endl; cout<<" #### ####"<<endl; cout<<" ###### ######"<<endl; cout<<"############################################################## ##################################"<<endl; cout<<"#...#......#.##...#......#.##...#......#.##------------------# #...#......#.##------------------#"<<endl; cout<<"###########################################------------------# ###############------------------#"<<endl; cout<<"#..#....#....##..#....#....##..#....#....##################### #..#....#....#####################"<<endl; cout<<"########################################## #----------# ############## #----------#"<<endl; cout<<"#.....#......##.....#......##.....#......# #----------# #.....#......# #----------#"<<endl; cout<<"########################################## #----------# ############## #----------#"<<endl; cout<<"#.#..#....#..##.#..#....#..##.#..#....#..# #----------# #.#..#....#..# #----------#"<<endl; cout<<"########################################## ############ ############## ############"<<endl; return 0; }