2016年11月10日 星期四

TIOJ 1667 - reversed

http://tioj.infor.org/problems/1667

反正範圍這麼小 就別用merge sort自虐了(?



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include<stdio.h>
int main(){
    int n;
    int a[103];
    while(scanf("%d",&n)!=EOF){
        int ans=0;
        for(int i=0;i<n;i++){
            scanf("%d",a+i);
            for(int j=0;j<i;j++){
                if(a[j]>a[i])ans++;
            }
        }
        printf("%d\n",ans);
    }
}

TIOJ 1665 - digit

http://tioj.infor.org/problems/1665

字串秒殺題



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include<iostream>
using namespace std;
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    while(cin>>s){
        cout<<s.length()<<'\n';
    }
}

TIOJ 1664 - t.g.i Friday!!

http://tioj.infor.org/problems/1664



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include<stdio.h>
#define E else if
#define P printf
int main(){
    short n;
    while(scanf("%d",&n)!=EOF){
        n%=7;
        if(n==0)P("Friday\n");
        E(n==1)P("Saturday\n");
        E(n==2)P("Sunday\n");
        E(n==3)P("Monday\n");
        E(n==4)P("Tuesday\n");
        E(n==5)P("Wednesday\n");
        E(n==6)P("Thursday\n");
    }
}

TIOJ 1025 - 數獨問題

http://tioj.infor.org/problems/1025

就直接DFS下去就解決了



 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<bits/stdc++.h>
using namespace std;

int s[10][10];
int ans;

void put(int x,int y){
    bool posi[10];
    bool bye=0;
    for(int i=x;i<=9;i++){
        for(int j=(i==x?y:1);j<=9;j++){
            if(s[i][j]==0){
                memset(posi,1,sizeof(posi));
                for(int ii=(i-1)/3*3+1,c=0;c<3;c++,ii++){
                    for(int jj=(j-1)/3*3+1,d=0;d<3;d++,jj++){
                        posi[s[ii][jj]]=0;
                    }
                }
                for(int k=1;k<=9;k++){
                    posi[s[i][k]]=0;
                    posi[s[k][j]]=0;
                }
                for(int k=1;k<=9;k++){
                    if(posi[k]){
                        s[i][j]=k;
                        put(i,j);
                    }
                }
                s[i][j]=0;
                bye=1;break;
            }
            if(i>=9 && j>=9){
                ans++;
                for(int ii=1;ii<=9;ii++){
                    for(int jj=1;jj<=9;jj++){
                        if(jj-1)cout<<" ";
                        cout<<s[ii][jj];
                    }
                    cout<<endl;
                }
                cout<<endl;
            }
        }
        if(bye)break;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            cin>>s[i][j];
        }
    }
    put(1,1);
    cout<<"there are a total of "<<ans<<" solution(s).";
}

TIOJ 1663 - + - * mod

http://tioj.infor.org/problems/1663

就降(?



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<bits/stdc++.h>
using namespace std;
int main(){
    int t,a,b;
    while(cin>>t>>a>>b){
        if(t==1)cout<<a+b<<endl;
        else if(t==2)cout<<a-b<<endl;
        else if(t==3)cout<<a*b<<endl;
        else cout<<a%b<<endl;
    }
}

TIOJ 1662 - 字串變化

http://tioj.infor.org/problems/1662

就這樣(?



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#include<cstdio>
char c;
int main(){
    while((c=getchar())){
        if(c==EOF)break;
        if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))c^=32;
        else if(c!='\n')c=32;
        putchar(c);
    }
}

TIOJ 1328 - 超基礎排序

http://tioj.infor.org/problems/1328

真的很基礎 連sort都用不到
仔細看好題目(?



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n,i;
    string jizz;
    while(cin>>n && n){
        getline(cin,jizz);
        getline(cin,jizz);
        for(i=1;i<=n;i++){
            if(i-1)cout<<' ';
            cout<<i;
        }
        cout<<'\n';
    }
}