import java.util.Scanner ;
import java.util.ArrayList ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        
        // 創造「鏈結」形式的陣列
        ArrayList <Integer> array = new ArrayList <Integer> () ;
        int amount = 6 ; // 陣列數量
        for ( int element = 0 ; element < amount ; element += 1 ) {
            int test = sc.nextInt () ; // 輸入「數字」
            array.add ( new Integer ( test ) ) ; // 將數字加入鏈結
        }
        
        // 進行反轉
        int head = 0 , end = amount - 1 ; // 前半部的元素;後半部的元素
        for ( head = 0 ; head < amount / 2 ; head += 1 ) {
            int test = array.get ( head ) ;
            array.set ( head , array.get ( end ) ) ;
            array.set ( end , test ) ;
            end -= 1 ;
        }
        
        // 顯示反轉後的鏈結陣列
        for ( int element = 0 ; element < amount - 1 ; element += 1 ) {
            System.out.print ( array.get ( element ) + " " ) ;
        }
        System.out.println ( array.get ( amount - 1 ) ) ;
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
import java.util.ArrayList ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        
        // 創造「鏈結」形式的陣列
        ArrayList <Integer> array = new ArrayList <Integer> () ;
        // 當輸入EOF時,代表結束,也就是系統無下一筆資料
        while ( sc.hasNext () ) {
            int test = sc.nextInt () ;
            array.add ( new Integer ( test ) ) ;
        }
        
        // 進行反轉
        int amount = array.size () ; // 元素總量
        int head = 0 , end = amount - 1 ; // 前半部的元素;後半部的元素
        for ( head = 0 ; head < amount / 2 ; head += 1 ) {
            int test = array.get ( head ) ;
            array.set ( head , array.get ( end ) ) ;
            array.set ( end , test ) ;
            end -= 1 ;
        }
        
        // 顯示反轉後的陣列
        for ( int element = 0 ; element < amount - 1 ; element += 1 ) {
            System.out.print ( array.get ( element ) + " " ) ;
        }
        System.out.println ( array.get ( amount - 1 ) ) ;
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

#include <stdio.h>
#include <math.h>
#define amount 6 

幻空 發表在 痞客邦 留言(0) 人氣()

#include <stdio.h>
#define amount 6 

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        
        for ( int data = sc.nextInt () ; data > 0 ; data -= 1 ) {
            int rowMax = sc.nextInt () ; // 方陣的「列」
            int columnMax = sc.nextInt () ; // 方陣的「行」
            int[][] array = new int [rowMax][columnMax] ; // 根據「row」和「column」創造方陣
            // 輸入方陣每一個元素的數值
            for ( int row = 0 ; row < array.length ; row += 1 ) {
                for ( int column = 0 ; column < array[row].length ; column += 1 ) {
                    array[row][column] = sc.nextInt () ;
                }
            }
            int graphValue = 1 ;
            
            // 對方陣內的每一個元素進行判斷
            for ( int row = 0 ; row < array.length ; row += 1 ) {
                for ( int column = 0 ; column < array[row].length ; column += 1 ) {
                    boolean edge = false ; // 是否為「邊界」,初始化為「否」
                    // 確認元素為圖形數值在進行判斷
                    if ( array[row][column] == graphValue ) {
                        // 上
                        if ( row + 1 < rowMax && array[row+1][column] == 0 ) {
                            edge = true ;
                        } // 下
                        else if ( row - 1 >= 0 && array[row-1][column] == 0 ) {
                            edge = true ;
                        } // 左
                        else if ( column - 1 >= 0 && array[row][column-1] == 0 ) {
                            edge = true ;
                        } // 右
                        else if ( column + 1 < columnMax && array[row][column+1] == 0 ) {
                            edge = true ;
                        }
                    }
                    // 根據「edge」進行輸出
                    if ( edge ) {
                        System.out.print ( "0 " ) ;
                    }
                    else {
                        System.out.print ( "_ " ) ;
                    }
                }
                System.out.println () ;
            }
            
            if ( data - 1 != 0 ) {
                System.out.println () ;
            }
        }
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
import java.lang.Math ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        int[] number = new int [6] ; // 創造一個數量為六的「int」陣列
        // 輸入六個數值
        for ( int element = 0 ; element < number.length ; element += 1 ) {
            number[element] = sc.nextInt () ;
        }
        
        // 進行陣列中所有元素立方和的計算
        int total = 0 ; // 紀錄立方和的變數,初始化為0
        for ( int element = 0 ; element < number.length ; element += 1 ) {
            total += (int) Math.pow ( number[element] , 3 ) ;
        }
        
        System.out.println ( total ) ; // 顯示立方和
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        int[] number = new int [6] ; // 創造一個元素數量為六的「int」陣列
        // 輸入六個數值
        for ( int element = 0 ; element < number.length ; element += 1 ) {
            number[element] = sc.nextInt () ;
        }
        
        // 進行反轉
        int seat = number.length - 1 ; // 由後往前,初始化為「最後一個元素」
        for ( int element = 0 ; element < seat ; element += 1 ) {
            // 將相對應的數值進行交換
            int test = number[element] ;
            number[element] = number[seat] ;
            number[seat] = test ;
            
            seat -= 1 ; // 下一個位置
        }
        
        // 顯示反轉後的陣列
        for ( int element = 0 ; element < number.length - 1 ; element += 1 ) {
            System.out.print ( number[element] + " " ) ;
        }
        System.out.println ( number[ number.length - 1 ] );
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

#include <stdio.h>
int main ( void ) {
    
    int number[100] = {} ; // 設定一個元素數量為100的「int」陣列
    int amount = 0 ; // 輸入的數字數量,同時兼具陣列的元素位置
    for ( amount = 0 ; amount < 100 ; amount += 1 ) {
        int test = scanf ( "%d" , &number[amount] ) ; // 輸入數字
        // 輸入「EOF」時,代表輸入結束
        if ( test == EOF ) {
            break ;
        } 
    } 
    
    // 進行反轉
    int seat = amount - 1 ; // 由後往前,初始化為「最後的元素位置」 
    int element = 0 ;  // 由前往後,初始化為「第一個元素位置」
    for ( element = 0 ; element < seat ; element += 1 ) {
        // 將相對應的數字進行交換 
        int test = number[element] ;
        number[element] = number[seat] ;
        number[seat] = test ;
        
        seat -= 1 ; // 下一個位置 
    } 
    
    // 顯示反轉後的陣列
    for ( element = 0 ; element < amount - 1 ; element += 1 ) {
        printf ( "%d " , number[element] ) ;
    } 
    printf ( "%d\n" , number[ amount - 1 ] ) ;
    
    return 0 ;
    

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        int[] number = new int [100] ; // 設定一個元素數量為100的「int」陣列
        int amount = 0 ; // 輸入的數字數量,同時兼具陣列的元素位置
        // 如果有下一筆資料就繼續輸入,沒有則離開( Ctrl Z ) 
        while ( sc.hasNext () ) {
            number[amount] = sc.nextInt () ; // 輸入數字
            amount += 1 ; // 數量加一,同時也代表下一個元素的位置
        }
        
        // 進行反轉
        int seat = amount - 1 ; // 由後往前,初始化為「最後的元素位置」
        for ( int element = 0 ; element < seat ; element += 1 ) {
            // 將相對應的數字進行交換
            int test = number[element] ;
            number[element] = number[seat] ;
            number[seat] = test ;
            
            seat -= 1 ; // 下一個位置
        }
        
        // 顯示反轉後的數字陣列
        for ( int element = 0 ; element < amount - 1 ; element += 1 ) {
            System.out.print ( number[element] + " " ) ;
        }
        System.out.println ( number[ amount - 1 ] ) ;
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        String string = sc.nextLine () ; // 以「字串」輸入資料
        String[] number = string.split ( " " ) ; // 以「空白」為切割點
        
        int seat = number.length - 1 ; // 由後向前,初始化為「最後一個元素的位置」
        String[] answer = new String [number.length] ; // 反轉後的陣列
        // 進行反轉
        for ( int element = 0 ; element < answer.length ; element += 1 ) {
            answer[element] = number[seat] ;
            seat -= 1 ;
        }
        
        // 顯示反轉後的陣列
        for ( int element = 0 ; element < answer.length - 1 ; element += 1 ) {
            System.out.print ( answer[element] + " " ) ;
        }
        System.out.println ( answer[ answer.length - 1 ] ) ;
        
        
    }
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

#include <stdio.h>
#include <string.h>
#include <ctype.h>
// 英文字母及數字加密:要加密的文字、移動數量 
char transformation ( char word , int move ) {
    
    int test = word + move ; // 進行加密
    // 優先確定字元是英文字母或數字,對於超過範圍的字元給予調整 
    if ( isdigit ( word ) && test > '9' ) {
        test -=  10 ;
    } 
    else if ( isupper ( word ) && test > 'Z' ) {
        test -= 26 ;
    }
    else if ( islower ( word ) && test > 'z' ) {
        test -= 26 ;
    }
    return (char) test ; // 轉換為字元後回傳 
    
}

幻空 發表在 痞客邦 留言(0) 人氣()

import java.util.Scanner ;
public class Main {
    
    public static void main ( String[] args ) {
        
        Scanner sc = new Scanner ( System.in ) ;
        // 測試的資料數量
        for ( int data = sc.nextInt () ; data > 0 ; data -= 1 ) {
            int[][] array = new int [3][5] ; // 行列式,以二維陣列表示
            // 輸入行列式
            for ( int row = 0 ; row < 3 ; row += 1 ) {
                for ( int column = 0 ; column < 3 ; column += 1 ) {
                    array[row][column] = sc.nextInt () ;
                    // 公式需要
                    switch ( column ) {
                        case 0 :
                            array[row][3] = array[row][column] ;
                            break ;
                        case 1 :
                            array[row][4] = array[row][column] ;
                            break ;
                    }
                }
            }
            
            Main MTool = new Main () ; // 要使用class Main中的方法,先實體化
            int add = MTool.count ( array , 1 , 0 ) ; // 計算正數總和
            int reduce = MTool.count ( array , -1 , 4 ) ; // 計算負數總和
            System.out.println ( ( add - reduce ) ) ; // 顯示行列式解答
        }
        
    }
    
    // 計算:行列式的陣列、移動數量、行的起始位置
    int count ( int[][] array , int move , int originalColumn ) {
        
        int answer = 0 ; // 計算後的答案
        for ( int amount = 0 ; amount < 3 ; amount += 1 ) {
            int column = originalColumn , test = 1 ; // 設定行的起始位置;計算數值
            for ( int row = 0 ; row < array.length ; row += 1 ) {
                test *= array[row][column] ; 
                column += move ; // 下一個行的位置
            }
            answer += test ;
            originalColumn += move ; // 下一個行的起始位置
        }
        return answer ; // 回傳計算好的結果
        
    }
   
}

幻空 發表在 痞客邦 留言(0) 人氣()

1 2
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。