1. 程式人生 > >【例題 8-2 UVA-1605】Building for UN

【例題 8-2 UVA-1605】Building for UN

sample require oca idea ngs space 相同 http promise

【鏈接】 我是鏈接,點我呀:)
【題意】


在這裏輸入題意

【題解】


兩層 然後n*n就夠了
第一層類似
aaa..
bbb..
ccc..
...
第二次則變成
abc....
abc....
abc....
....
這樣就能保證每個字母都和其他的字母有相鄰的了。(不同層的相同位置

【代碼】

/*
    1.Shoud it use long long ?
    2.Have you ever test several sample(at least therr) yourself?
    3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things? 5.init the used array or any value? 6.use error MAX_VALUE? 7.use scanf instead of cin/cout? 8.whatch out the detail input require */ /* 一定在這裏寫完思路再敲代碼!!! */ #include <bits/stdc++.h> using namespace std; const
int N = 50; int n; char idx[N+10]; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); for (int i = 1;i <= N;i++) if (i <= 26){ idx[i] = 'a'+i-1; }else{ idx[i] = 'A'
+i-26-1; } int kase = 0; while (cin >> n){ if (kase>0) cout << endl; kase++; cout << 2 <<' '<<n << ' '<<n<<endl; for (int i = 1;i <= n;i++){ for (int j = 1;j <= n;j++) cout << idx[i]; cout<<endl; } cout << endl; for (int i = 1;i <= n;i++) { for (int j = 1;j <= n;j++) cout << idx[j]; cout << endl; } } return 0; }

【例題 8-2 UVA-1605】Building for UN