把#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <vector> #include <map> #include <vector> #include <string> #include <cstring> #define fast ios::sync_with_stdio(false),cin.tie(0) using namespace std; typedef pair<int, int> PII; typedef long long LL; const int N = 2e5+10; int T, t; string s[3]; void init() { /* #### #### #### # # # # # # # # #*/ // 第一行,中间行,和最后一行 // 构造成 #### #### #### for(int i = 0; i < 3; i ++ ) { if(i) s[0] += " "; s[0] += "###"; for(int j = 0; j < t; j ++ ) s[0] += "#"; } // 上半部分 // 构造成 # # # # s[1] += "# "; for(int i = 0; i < t; i ++ ) s[1] += " "; s[1] += "# #"; for(int i = 0; i < 2 * t + 5; i ++ ) s[1] += " "; s[1] += "#"; // 下半部分 // 构造成 # # # # # s[2] += "# "; for(int i = 0; i < t; i ++ ) s[2] += " "; s[2] += "# # "; for(int i = 0; i < t; i ++ ) s[2] += " "; s[2] += "#"; for(int i = 0; i < t + 3; i ++ ) s[2] += " "; s[2] += "#"; } int main() { scanf("%d", &t); int n = t * 2 + 5; init(); for(int i = 1; i <= n; i ++ ) { if(i == 1 || i == n || i == (n + 1)/2) cout << s[0] << endl; else if(i < (n + 1) / 2) cout << s[1] << endl; else cout << s[2] << endl; } return 0; } 这段代码变成C语言
时间: 2024-03-23 08:41:39 浏览: 149
把#include <iostream>改为#include <stdio.h>,把using namespace std;删除,将cout改为printf即可:
```c
#include <stdio.h>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <vector>
#include <string>
#include <cstring>
#define fast ios::sync_with_stdio(false),cin.tie(0)
typedef pair<int, int> PII;
typedef long long LL;
const int N = 2e5+10;
int T, t;
char s[3][N];
void init()
{
// 第一行,中间行,和最后一行
// 构造成 #### #### ####
for(int i = 0; i < 3; i ++ )
{
if(i) strcat(s[0], " ");
strcat(s[0], "###");
for(int j = 0; j < t; j ++ ) strcat(s[0], "#");
}
// 上半部分
// 构造成 # # # #
s[1][0] = '#';
s[1][1] = ' ';
for(int i = 2; i < t+2; i ++ ) s[1][i] = '#';
s[1][t+2] = ' ';
for(int i = t+3; i < 2 * t + 5; i ++ ) s[1][i] = ' ';
s[1][2*t+5] = '#';
// 下半部分
// 构造成 # # # # #
s[2][0] = '#';
s[2][1] = ' ';
for(int i = 2; i < t+2; i ++ ) s[2][i] = '#';
s[2][t+2] = ' ';
for(int i = t+3; i < 2 * t + 3; i ++ ) s[2][i] = ' ';
s[2][2*t+3] = '#';
for(int i = 2*t+4; i < t+7; i ++ ) s[2][i] = ' ';
s[2][t+7] = '#';
}
int main()
{
scanf("%d", &t);
int n = t * 2 + 5;
init();
for(int i = 1; i <= n; i ++ )
{
if(i == 1 || i == n || i == (n + 1)/2) printf("%s\n", s[0]);
else if(i < (n + 1) / 2) printf("%s\n", s[1]);
else printf("%s\n", s[2]);
}
return 0;
}
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)