2017年4月28日 星期五

[C_AR168-易] 最大方塊區域

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=15066

#include<stdlib.h>
#include<stdio.h>
int main(){
int n,arr[20][20],i,j,m,p,q,num;
while(scanf("%d",&n)!=EOF){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
scanf("%d",&arr[i][j]);
}
}
scanf("%d",&num);
for(m=n;m>0;m--){
for(i=0;i<=n-m;i++){
for(j=0;j<=n-m;j++){
int b=1;
for(p=0;p<m;p++){
for(q=0;q<m;q++){
if(arr[p+i][q+j]!=num){
b=0;
break;
}
}
}
if(b){
goto z ;
}
}
}
}
z:
printf("%d\n",m);
}
/*題目:[C_AR168-易] 最大方塊區域
作者:1010
時間:西元 2017 年 4 月 */
}

這題簡單來說就是利用一個mask去罩,從最大值n開始逐一遞減

2017年4月10日 星期一

[C_AR151-易] 井字遊戲判斷

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=24317

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
int arr[][]=new int[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
arr[i][j]=scn.nextInt();
String s="";
for(int i=0;i<3;i++){
if(arr[i][0]==arr[i][1]&&arr[i][1]==arr[i][2]&&arr[i][0]==n){
s+="All "+n+"'s on row "+i+"\n";
}
}
for(int i=0;i<3;i++){
if(arr[0][i]==arr[1][i]&&arr[1][i]==arr[2][i]&&arr[0][i]==n){
s+="All "+n+"'s on column "+i+"\n";
}
}
if(arr[0][0]==arr[1][1]&&arr[1][1]==arr[2][2]&&arr[0][0]==n)
s+="All "+n+"'s on diagonal\n";
if(arr[0][2]==arr[1][1]&&arr[1][1]==arr[2][0]&&arr[0][2]==n)
s+="All "+n+"'s on subdiagonal\n";
if(s.length()>0)
System.out.print(s);
else
System.out.println("There is no line with all "+n);
}
/*題目:[C_AR151-易] 井字遊戲判斷
作者:1010
時間:西元 2017 年 4 月 */
}

這題就是把八種連線可能方式一一去檢查,若完全無則輸出There is no line with all ?
(?為該數)

[C_AR130-易] 拉彩金

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=21811

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
while(n--!=0){
int num=scn.nextInt(),arr[]=new int[num],max=0;
for(int i=0;i<num;i++){
arr[i]=scn.nextInt();
}
int sum=0,max_sum=0;
for(int j=0;j<num;j++)
{
sum+=arr[j];
sum=Math.max(0,sum);
max_sum=Math.max(max_sum,sum);
}
System.out.println(max_sum);
}
}
/*題目:[C_AR130-易] 拉彩金
作者:1010
時間:西元 2017 年 4 月 */
}

這題陣列走訪,取得最少時間複雜度用單迴圈就行了,每走訪一個就加到sum,並每次判斷sum是否小於0若成立歸零Math.max()就是比較大小函式,比對確認後最後再比目前最大的數字並存max_sum

2017年4月9日 星期日

[C_MM246-易] 矩陣反轉

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=15134

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNext()){
int x=scn.nextInt(),y=scn.nextInt(),arr[][]=new int[y][x];
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
arr[j][i]=scn.nextInt();
for(int i=0;i<y;i++){
for(int j=0;j<x;j++){
if(j!=0)
System.out.print(" ");
System.out.print(arr[i][j]);
}
System.out.println();
}
}
}
/*題目:[C_MM246-易] 矩陣反轉
作者:1010
時間:西元 2017 年 4 月 */
}

這題矩陣反轉就是建立二維陣列下去實作,輸入時索引值顛倒

[C_SO37-易] 不誠實不給獎

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=15760

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt(),arr[]=new int[n],count=0;
for(int i=0;i<n;i++)
arr[i]=scn.nextInt();
Arrays.sort(arr);
for(int i=n-1;i>=0;i--){
if(count==2)
break;
else if(arr[i]<90){
System.out.println("x");
count++;
break;
}
else if(arr[i]%2!=0){
continue;
}
else{
System.out.println(arr[i]);
count++;
}
}
if(count==1)
System.out.println("x");
}
/*題目:[C_SO37-易] 不誠實不給獎
作者:1010
時間:西元 2017 年 4 月*/
}

這題就是找出前兩名必須要90分以上若無就x注意以下測資
3
98 97 97
必須要輸出
98
x
所以要有一個計數器count紀錄印出幾個了

2017年4月8日 星期六

[C_SO45-易] 混合數列

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=22801

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int arr[]=new int [50],count=0;
for(int i=1;i<=25;i++){
arr[count++]=(int)Math.pow(3, i);
arr[count++]=(int)Math.pow(4, i);
}
Arrays.sort(arr);
int j=0,tot=0,n=scn.nextInt();
for(;j<n;j++)
tot+=arr[j];
System.out.println(arr[j-1]+","+tot);
}
/*題目:C_SO45-易 混合數列
作者:1010
時間:西元 2017 年 4 月*/
}

這題就依序地將3與4的次方數1~25算出來存入陣列中(題目設定最大50代表各25個次方)
最後一定要再做排序

[C_ST22-易] 迴文字串 II

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=1690

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
char s[]=scn.nextLine().toCharArray();
for(int i=s.length-1;i>=0;i--){
if(s[i]>64&&s[i]<91)
System.out.printf("%c",s[i]+32);
else if(s[i]>96&&s[i]<123)
System.out.printf("%c",s[i]-32);
else
System.out.print(s[i]);
}
System.out.println();
}
/*題目:C_ST22-易 迴文字串 II
作者:1010
時間:西元 2017 年 4 月*/
}

我第一種寫法是利用字串去實作並利用toCharArray然後在利用字串toUpperCase、toLowerCase系統竟然回傳值1
所以最後只好乖乖地用成字串陣列依序判斷翻轉,那一樣也是利用ASCII碼判斷大小寫
A~Z是65~90
a~z是97~122

[C_ST03-易] 萬國碼轉成對應字元

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=211

#include<stdlib.h>
int main(){
int n;
scanf("%d",&n);
printf("%c\n",n);
/*題目:C_ST03-易 萬國碼轉成對應字元
作者:1010
時間:西元 2017 年 4 月*/
}

這題應該是ITSA所有題目程式碼最少行的題目吧...
這題很直覺的直接把獨到的整數用%c字元他就會自動轉成相對應的ASCII碼符號了

[C_MM261-易] 數字的出現次數

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=15856

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt(), tot = n / 100 * 20;
Boolean b = true;
if (n / 100 == 8) {
tot += n % 100 + 1;
}
n %= 100;
tot += n / 10;
if (n > 88 && n / 10 != 8)
b = false;
if (n >= 80 && n < 90)
tot += n - 79;
else if (n >= 90)
tot += 10;
if (n >= 98)
tot++;
n %= 10;
if (n >= 8 && n <= 9 && b)
tot++;
System.out.println(tot);
}
/*題目:C_MM261-易 數字的出現次數
作者:1010
時間:西元 2017 年 4 月*/
}
這題就是算有幾個8注意當800多時是例外每增加一個數字就加一

2017年4月7日 星期五

[C_AR90-易] 天堂島居留證

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=11138

#include<stdlib.h>
int main(){
int n;
scanf("%d",&n);
while(n--){
char arr[13];
scanf("%s",arr);
int num=0,weight[]={1,3,5,2,4,6,1,3,5,2,4,6},i=0;
for(;i<12;i++){
num+=(arr[i]-'0')*weight[i];
}
if(10-(num%10)==arr[12]-'0')
printf("yes\n");
else
printf("no\n");
}
/*題目:C_AR90-易 天堂島居留證
作者:1010
時間:西元 2017 年 4 月*/
}

這題用java交了21次始終回傳值1我也搞不懂問題在哪(但有人java繳交AC),最後索性用C寫竟然一次就過= =
這題就跟身分證檢驗類似,依照他的說明權重運算與最後一位相同就輸出yes反之

[C_AR92-易] 和尚端湯上塔

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=13580

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNext()){
String arr[]=scn.nextLine().split(" ");
int count=0;
for(int i=1;i<=10;i++){
if(Integer.parseInt(arr[i-1])%i!=0)
count++;
}
if(count<=3)
System.out.println("yes");
else
System.out.println("no");
}
}
/*題目:C_AR92-易 和尚端湯上塔
作者:1010
時間:西元 2017 年 4 月*/
}

這題就是把每位數去除若無法整除就表示滑倒,滑倒3次以內(包含3)就輸出yes反之
總共十層所以被除數依序從1~10

[C_AR94-易] 洗刷刷

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=13624

#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(){
char str1[100],str2[100];
scanf("%s%s",str1,str2);
int i=0;
for(i=0;i<strlen(str1);i++){
if(str1[i]==(str2[i])||(abs((str1[i]-'0')-(str2[i]-'0'))>1&&abs((str1[i]-'0')-(str2[i]-'0'))!=4))
printf("和");
else if(abs((str1[i]-'0')-(str2[i]-'0'))==4){
if(str1[i]-'0'>str2[i]-'0')
printf("輸");
else
printf("贏");
}
else{
if(str1[i]-'0'>str2[i]-'0')
printf("贏");
else
printf("輸");
}
}
printf("\n");
/*題目:C_AR94-易 洗刷刷
作者:1010
時間:西元 2017 年 4 月 7日*/
}

依照題意兩數相差大於1就是和還有一個例外就是1比5大其餘就按照比大小去比
注意!ITSA似乎不能接受JAVA國字的題目(使用萬國碼也無法AC)

[C_AR73-易] 兔子生育計算

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=3693

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
while(n--!=0){
int num=scn.nextInt(),i=1,a=1,b=1,fab;
while(i<=num){
if(i!=1)
System.out.print(" ");
if(i==1|i==2)
System.out.print("1");
else{
fab=a+b;
a=b;
b=fab;
System.out.print(fab);
}
i++;
}
System.out.println();
}
}
/*題目:C_AR73-易 兔子生育計算
作者:1010
時間:西元 2017 年 4 月 7日*/
}
這題就只是單存的費事數列

2017年4月6日 星期四

[C_AR61-易] 配對

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?id=3529

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
while(n--!=0){
int arr[][]=new int[4][4];
for(int i=0;i<4;i++){
scn.next();
while(true){
int num=scn.nextInt();
if(num==0)
break;
else
arr[i][num-1]=1;
}
}
int count=0;
for(int i=0;i<4;i++){
if(arr[0][i]==1)
continue;
for(int j=0;j<4;j++){
if(arr[1][j]==1)
continue;
for(int k=0;k<4;k++){
if(arr[2][k]==1)
continue;
for(int l=0;l<4;l++){
if(arr[3][l]==1)
continue;
else{
int temp[]=new int[4];
temp[i]=1;temp[j]=1;temp[k]=1;temp[l]=1;
if(temp[0]+temp[1]+temp[2]+temp[3]==4){
if(count==0)
System.out.println("ABCD");
System.out.println((i+1)+""+(j+1)+""+(k+1)+""+(l+1));
count++;
}
}
}
}
}
}
if(count==0)
System.out.println("No Solution");
System.out.println();
}
}
/*題目:C_AR61-易 配對
作者:1010
時間:西元 2017 年 4 月 7日*/
}
這題就只是考陣列而已簡單來說找出每位地差集1代表沒興趣0表示有興趣,4個迴圈下去跑組合,每次還需要盤段是否為"愉快"的狀態(表1234每位都有分配到沒重複搶人狀況發生),結束時必須在換一行

Q10093: An Easy Problem!

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1034

import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNext()) {
char arr[]=scn.nextLine().trim().toCharArray();
int tot=0,max=1;
for(int i=0;i<arr.length;i++){
if(arr[i]>='0'&&arr[i]<='9'){
if(arr[i]-'0'>max){
max=arr[i]-'0';
}
tot+=arr[i]-'0';
}
else if(arr[i]>='A'&&arr[i]<='Z'){
if(arr[i]-'A'+10>max){
max=arr[i]-'A'+10;
}
tot+=arr[i]-'A'+10;
}
else if(arr[i]>='a'&&arr[i]<='z'){
if(arr[i]-'a'+36>max){
max=arr[i]-'a'+36;
}
tot+=arr[i]-'a'+36;
}
}
int i=0;
for(i=max;i<62;i++){
if(tot%i==0){
System.out.println(i+1);
break;
}
}
if(i==62)
System.out.println("such number is impossible!");
}
}
/*題目:Q10093: An Easy Problem!
作者:1010
時間:西元 2017 年 4 月 7日*/
}

這題主要是找該數的每位數最大的基底,最後再查看該數能夠被最小基底的數整除的基底數