---
# System prepended metadata

title: 11/05 TOJ110大魔王但很有挑戰性

---

# 11/05 TOJ110大魔王但很有挑戰性
### 更:11/06已成功，微調r5解決
TOJ110 (https://toj.tfcis.org/oj/pro/110/)
想法
    r0 -- *
    r1 -- 中間層數、"*"數不一定
    r2 -- 最長 (三角形底)
    r3 -- 兩底之間
    r4 -- 同r2
    r5 -- 同r1，但方向相反，數量也不同
    r6 -- *
    
--------------------------------
原本錯誤版本
```C++=
#include<iostream>

using namespace std;

int main(){
	int n;	cin>>n;
	for (int i=0;i<n;i++) {
		int a;	cin>>a;
		for (int s0=0;s0<(a-1);s0++)
			cout<<" ";
		cout<<"*\n";
		for (int r1=1;r1<=(a-4);r1++) {
			for (int s1=0;s1<(a-r1-1);s1++)
				cout<<" ";
			for (int j=0;j<(1+2*r1);j++)
				cout<<"*";
			cout<<'\n';
		}
		for (int r2=0;r2<(2*a-1);r2++) {
			cout<<"*";
		}
		cout<<'\n'<<" ";
		for (int r3=0;r3<(a*2-3);r3++) {
			cout<<"*";
		}
		cout<<'\n';
		for (int r4=0;r4<(2*a-1);r4++) {
			cout<<"*";
		}
		cout<<'\n';
		for (int r5=1;r5<=(a-4);r5++) {									//r5空格處有問題 
			for (int s5=0;s5<(a-r5-1);s5++)								//數量也有 
				cout<<" ";
			for (int j=0;j<(1+2*r5);j++)
				cout<<"*";
			cout<<'\n';
		}
		for (int s6=0;s6<(a-1);s6++)
			cout<<" ";
		cout<<"*\n";
	}


	return 0;
}
```
目前剩下r5還沒搞定，其他Bug還沒找到

------------------------
正確版:
```c++=
#include<iostream>

using namespace std;

int main(){
	int n;	cin>>n;
	for (int i=0;i<n;i++) {
		int a;	cin>>a;
		for (int s0=0;s0<(a-1);s0++)
			cout<<" ";
		cout<<"*\n";
		for (int r1=1;r1<=(a-4);r1++) {
			for (int s1=0;s1<(a-r1-1);s1++)
				cout<<" ";
			for (int j=0;j<(1+2*r1);j++) {
				cout<<"*";
			}
			cout<<'\n';
		}
		for (int r2=0;r2<(2*a-1);r2++) {
			cout<<"*";
		}
		cout<<'\n'<<" ";
		for (int r3=0;r3<(a*2-3);r3++) {
			cout<<"*";
		}
		cout<<'\n';
		for (int r4=0;r4<(2*a-1);r4++) {
			cout<<"*";
		}
		cout<<'\n';
		for (int r5=0;r5<(a-4);r5++) {							
			for (int s5=0;s5<(3+r5);s5++) 
				cout<<" ";
			for (int k=0;k<(1+2*(a-4)-2*r5);k++)
				cout<<"*";
			cout<<'\n';
		}
		for (int s6=0;s6<(a-1);s6++)
			cout<<" ";
		cout<<"*\n";
	}


	return 0;
}
```
不確定是否是最快方法，但已正確解決問題
###### time:11/06 a.m.11:13



