| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10063 | moocHW2b |
|
| 10064 | moocHW2c |
|
| 10900 | Transpose of A Matrix |
|
| 10903 | Postman |
|
| 11533 | Christmas tree |
|
| 11534 | GCD |
|
Description
讀取一個整數 N (0<N<50),輸出一個 N-by-N 的矩陣,對角線上的值是 2,對角線兩旁是 -1,其餘位置則
都是 0。
例如 N 的值如果是 5,輸出結果會長得像下面這樣。
注意:包含最後一列在內,每一列結尾都有一個換行;此外每個數目佔了三個字元寬度,因此 2 的前面會有兩個空格,0 的前面也會有兩個空格,但是 -1的前面只有一個空格。
Input
N 是一個整數,範圍是 0<N<50。
Output
如題目所描述的 N-by-N 矩陣。注意換行和空格。
(Sample Output 因系統問題無法正確顯示,請以題目中敘述的格式為準 )
Sample Input Download
Sample Output Download
Tags
Discuss
Description
輸入一個整數 N (10<N<10000000),譬如 N 的值是 10413,把這個數字切成兩段有底下幾種切法,{1,0413}、{10,413}、{104,13}以及 {1041,3},其中 {1,0413} 和 {104,13} 兩種切法,如果拿大數除以小數,可以除得盡,0413 除以 1 的商是 413 (前面第一個 0忽略),104 除以 13 的商則是 8,你的程式要能求出其中最小的商,在這個例子就是 8。
假如不論哪一種切法,都沒有整除的情況發生,則輸出 0。
再舉一些例子,譬如 N的值是 3897433,答案是 9,因為 {3897,433}。譬如 N的值 3343674,答案是 11。
又譬如 N 的值是 100,則答案是 0。又譬如 N是 795則答案是 0。
要注意程式碼不要發生除以 0 的情況。
Input
一個整數 N,10<N<10000000。
Output
如題目描述,將 N 分成兩段之後,大數除以小數能夠得到的最小的商。輸出的答案後面要加換行字元。
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a matrix A (you can consider it as a 2-D array), print out transpose of A.
Note: Try to use dynamic memory management to finish this problem.
main.c
#include <stdio.h>
#include "function.h"
int main(void) {
int **mat;
int m, n, i;
scanf("%d %d", &m, &n);
mat = allocateMat(m, n);
readInput(mat, m, n);
printResult(mat, m, n);
// Be sure to release acquired memory space
for(i=0; i<m; i++)
free(mat[i]);
free(mat);
return 0;
}
function.h
#ifndef FUNCTION_H #define FUNCTION_H int** allocateMat(int, int); void readInput(int**, int, int); void printResult(int**, int, int); #endif
Input
First line has two integers, indicates A is M rows by N columns. Next M lines are the content of A, each line has N integers.
Output
N lines, each line contains M integers. Values are separated by a blank. There’s a blank and a newline at the end of each line.
Sample Input Download
Sample Output Download
Partial Judge Code
10900.cPartial Judge Header
10900.hTags
Discuss
Description
Collected letters would be classified by zip code. After that, certain postman likes to sort the letters by sender’s name. Here’s an example:
30013 Xiao 10850 Wang
23679 Huang 23679 Huang
24241 Chen -> 24241 Chen
89346 Hsu 30013 Tsai
10850 Wang 30013 Xiao
30013 Tsai 89346 Hsu
Letters would be arranged firstly by zip code, secondly by name once zip codes are the same. Sort the letters with the name by the weight of the string from high to low. The weight of string is defined as following:
Lower case letters: a ~ z corresponds to 1 ~ 26
Upper case letters: A ~ Z corresponds to 2 ~ 27
| letter | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
| weight | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| letter | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| weight | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
For example, the weight of "Allen" is 2 + 12 + 12 + 5 + 14 = 45
Once the zip code and the weight are the same. Dictionary order is used for sorting names. As an example, the weight of “Tsai” and “Xiao” are the same, “T” is previous than “X”, which results the order: 30013 Tsai, 30013 Xiao.
main.c
#include <stdio.h>
#include <stdlib.h>
#include "function.h"
int main(void){
int n;
int i;
Letter *letters;
// Read inputs
scanf("%d", &n);
letters = (Letter*)malloc(sizeof(Letter)*n);
for(i=0; i<n; i++)
scanf("%d %s", &(letters[i].zipcode), letters[i].name);
// Sort the data
qsort((void*)letters, n, sizeof(Letter), compare);
// Output result
for(i=0; i<n; i++)
printf("%d %s\n", letters[i].zipcode, letters[i].name);
free(letters);
return 0;
}
function.h
#ifndef FUNCTION_H
#define FUNCTION_H
typedef struct {
int zipcode;
char name[15];
} Letter;
int compare(const void *, const void *);
#endif
Input
First line is an integer N, number of the letters. The following N lines have an integer, zip code, followed by a name. N is less than 10 million.
Output
Sorted result, N lines, each line contains the zip code and a name separated by a space.
Sample Input Download
Sample Output Download
Partial Judge Code
10903.cPartial Judge Header
10903.hTags
Discuss
Description
請印出聖誕樹
Input
會給3個數字level, width, height
level: 表示樹葉部份的層數,每層為上一層加2(e.g. 1 3 5 7 ...), 1 <= level <= 20
width: 表示樹木的寬度,寬度只會是奇數, 1 <= width <= 39
height: 表示樹木的高度,0 <= height <= 9
Output
請參考sample IO (可以載下來觀看),樹木的寬度可能會超過樹葉部份的寬度,請以最寬的部份為基準,碰在畫面最左邊(如果height是0,不影響畫的位置),樹木的中心點會剛好對應整棵樹的中心點(整棵樹左右會對稱)
每行最右邊的'*'號,請接換行符號('\n'),不要輸出多餘的符號如空白' '
sample IO共有4個例子,用'---'做區隔,實際的IO只會有三個數字,並且只需要輸出一次聖誕樹即可
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given two positive integers a and b, compute the greatest common divisor (GCD) of a and b. The GCD of a and b is the biggest integer that can divide a and b with no reminder.
Input
First line contains a positive integer t (t<=10000), which indicates the number of test cases in the input. In the next t lines, each line contains two positive integers a, b, which are smaller than or equal to 105.
Output
For each case, output the GCD of a and b in a line.