標題:
APCS 實作題 10503 - 2
[打印本頁]
作者:
ray
時間:
2019-12-21 18:14
標題:
APCS 實作題 10503 - 2
https://zerojudge.tw/ShowProblem?problemid=b965
作者:
陳思惟
時間:
2019-12-28 18:27
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class B965 {
public static void main(String[] args) {
StreamTokenizer cin = new StreamTokenizer(new BufferedReader(
new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
try {
while (cin.nextToken() != StreamTokenizer.TT_EOF) {
// input
int r = (int) cin.nval;
cin.nextToken();
int c = (int) cin.nval;
cin.nextToken();
int m = (int) cin.nval;
int method[] = new int[m];
int initArr[][] = new int[r][c];
int nowArr[][] = new int[r][c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
cin.nextToken();
initArr[i][j] = (int) cin.nval;
}
}
for (int i = 0; i < m; i++) {
cin.nextToken();
method[i] = (int) cin.nval;
}
// do
nowArr = initArr;
for (int i = m - 1; i >= 0; i--) {
if (method[i] == 0) { // 旋
nowArr = spin(nowArr);
} else { // 翻
nowArr = flip(nowArr);
}
}
for (int i = 0; i < nowArr.length; i++) {
for (int j = 0; j < nowArr[0].length; j++)
out.print(nowArr[i][j]+" ");
out.println("");
}
out.flush();
}
} catch (IOException e) {
// TODO 自動產生的 catch 區塊
e.printStackTrace();
}
}
static int[][] spin(int[][] in) { // 旋轉
int[][] tmp = new int[in[0].length][in.length];
for (int k = 0; k < in[0].length; k++) {
for (int n = 0; n < in.length; n++) {
tmp[k][n] = in[n][in[0].length-k-1];
}
}
return tmp;
}
static int[][] flip(int[][] in) { // 翻轉
int[][] tmp = new int[in.length][in[0].length];
for (int k = in.length - 1; k >= 0; k--) {
for (int n = 0; n < in[0].length; n++)
tmp[k][n] = in[in.length - k - 1][n];
}
return tmp;
}
}
複製代碼
作者:
李知易
時間:
2019-12-28 20:01
本帖最後由 李知易 於 2019-12-28 20:03 編輯
import java.io.*;
import java.util.*;
public class B965 {
B965()
{
StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
try{
while(cin.nextToken()!=StreamTokenizer.TT_EOF)
{
int r = (int)cin.nval;
cin.nextToken();
int c = (int)cin.nval;
cin.nextToken();
int m = (int)cin.nval;
int[][] b = new int[r][c];
//r , c 行列數
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
cin.nextToken();
b[i][j] = (int)cin.nval;
}
}
int[] mn = new int[m];
for(int i = 0 ; i < mn.length ; i++)
{
cin.nextToken();
mn[i] = (int)cin.nval;
}
for(int x = m-1; x >= 0; x--)
{
if(mn[x] == 0)
{
int[][] re = new int[c][r];
for(int i = 0; i < c; i++)
{
for(int j = 0; j < r; j++)
{
re[i][j] = b[j][c-1-i];
}
}
int t = r;
r = c;
c = t;
b = re;
}
else if(mn[x] == 1)
{
int[][] re = new int[r][c];
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
re[i][j] = b[r-1-i][j];
}
}
b = re;
}
}
out.print(r+" "+c);
out.println();
for(int i = 0; i < r; i++)
{
for(int j = 0; j < c; j++)
{
if(j != 0)
out.print(" ");
out.print(b[i][j]);
}out.println();
}
out.println();
out.flush();
}
}catch(Exception e){}
}
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
new B965();
}
}
複製代碼
作者:
陳泓瑜
時間:
2019-12-28 20:02
package com.brixpert.dab;
import java.io.*;
public class B965 {
B965()
{
StreamTokenizer sti = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
try
{
while(sti.nextToken() != StreamTokenizer.TT_EOF)
{
int h,w,f,tmp;
h = (int)sti.nval;
sti.nextToken();
w = (int)sti.nval;
sti.nextToken();
f = (int)sti.nval;
int n[][] = new int[h][w];
int nf[] = new int[f];
for(int i = 0; i < h; i++)
{
for(int j = 0; j < w; j++)
{
sti.nextToken();
n[i][j] = (int)sti.nval;
}
}
for(int i = 0; i < f; i++)
{
sti.nextToken();
nf[i] = (int)sti.nval;
}
//-------------------------------------------------------------------------------------------------
for(int r = f-1; r >= 0; r--)
{
if(nf[r] == 1)
{
//flip
int x[][] = new int[h][w];
for(int i = 0; i < h; i++)
{
for(int j = 0; j < w; j++)
{
x[i][j] = n[h-1-i][j];
}
}
n = x;
}
else
{
//turn
int x[][] = new int[w][h];
for(int i = 0; i < w; i++)
{
for(int j = 0; j < h; j++)
{
x[i][j] = n[j][w-1-i];
}
}
tmp = h;
h = w;
w = tmp;
n = x;
}
}
//output
pw.print(h+" "+w+"\n");
for(int i = 0; i < h; i++)
{
for(int j = 0; j < w; j++)
{
if(j != 0)
pw.print(" ");
pw.print(n[i][j]);
}
pw.println();
}
pw.flush();
}
}catch(Exception exc)
{
pw.print(exc.toString());
pw.flush();
}
}
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
new B965();
}
}
/*
____ ___ __ _____
| _ \ / _ \ / /| ____|
| |_) | (_) |/ /_| |__
| _ < \__, | '_ \___ \
| |_) | / /| (_) |__) |
|____/ /_/ \___/____/ ____ _____ ___ _______ ______ _____ _______ ______ ___ __ _ _
| | | __ \ /\ | _ \| __ \(_) \ / / __ \| ____| __ \__ __|____ / _ \/_ | || |
| |__ _ _ | | | | / \ | |_) | |__) |_ \ V /| |__) | |__ | |__) | | | / / | | || | || |_
| '_ \| | | | | | | |/ /\ \ | _ <| _ /| | > < | ___/| __| | _ / | | / /| | | || |__ _|
| |_) | |_| | | |__| / ____ \| |_) | | \ \| |/ . \| | | |____| | \ \ | | / / | |_| || | | |
|_.__/ \__, | |_____/_/ \_\____/|_| \_\_/_/ \_\_| |______|_| \_\ |_| /_/ \___/ |_| |_|
__/ |
|___/ ___ ___ __ ___ __ ___ ___ ___ __ ___ _____ ___ _______ __ __ _______ _____
| | |__ \ / _ \/_ |/ _ \/_ |__ \ |__ \ / _ \ /_ |/ _ \ _| ____|/ _ \ / / ____| \/ |__ __| / _ \ \
__ _| |_ ) | | | || | (_) || | ) | ) | (_) | | | (_) (_) |__ | (_) | | | __| \ / | | |_| || (_) | |
/ _` | __| / /| | | || |\__, || | / / / / > _ < | |\__, | |___ \ > _ <| | | |_ | |\/| | | |_ _> _ <| |
| (_| | |_ / /_| |_| || | / / | |/ /_ _ / /_| (_) | | | / / _ ___) | (_) | | |__| | | | | | | |_|| (_) | |
\__,_|\__| |____|\___/ |_| /_(_)|_|____(_)____|\___/ |_| /_/ (_)____/ \___/| |\_____|_| |_| |_| \___/| |
\_\ /_/
*/
複製代碼
作者:
黃璽安
時間:
2019-12-28 20:07
import java.io.*;
import java.util.Arrays;
public class B965{
B965()
{
StreamTokenizer cin = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
try
{
while(cin.nextToken() != StreamTokenizer.TT_EOF)
{
int R = (int)cin.nval;
cin.nextToken();
int C = (int)cin.nval;
cin.nextToken();
int M = (int)cin.nval;
int a[][] = new int [R][C];
int b[] = new int [M];
for(int i = 0; i<R; i++)
for(int j = 0; j<C; j++)
{
cin.nextToken();
a[i][j] = (int)cin.nval;
}
for(int i = 0; i<M; i++)
{
cin.nextToken();
b[i] = (int)cin.nval;
}
for(int k = M-1; k>=0; k--)
{
if(k == 0)
{
int d[][] = new int [C][R];
for(int i = 0; i<C; i++)
for(int j = 0; j<R; j++)
{
d[i][j] = a[j][C-1-i];
}
a=d;
int t=C;
C=R;
R=t;
}
else
{
int c[][] = new int [R][C];
for(int i = 0; i<R; i++)
for(int j = 0; j<C; j++)
{
c[i][j] = a[R-1-i][j];
}
a=c;
}
}
for(int i = 0; i<R; i++){
for(int j = 0; j<C; j++)
{
if(j!=0)
{
out.print(" ");
}
out.print(a[i][j]);
}
out.println();
}
out.println();
out.flush();
}
}catch(Exception e)
{
out.println(e.toString());
out.flush();
}
}
public static void main(String[] args)
{
// TODO 自動產生的方法 Stub
new B965();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2