發表文章

目前顯示的是 2016的文章

[UVA494]Kindergarten Counting Game

#include<cstdio> #include<cstring> #include<cctype> #define maxn 1000 int main(void) { char s[maxn]; memset(s,' ',sizeof(s)); while(gets(s)) { int len = strlen(s), count = 0, a = 0;//a = 0 目前為字母 1為其他非字母 for(int i=0;i<len;i++) { if(isalpha(s[i]) && !a) { a = 1; count++; } else if(!isalpha(s[i]) && a) a = 0; } printf("%d\n",count); } return 0; }

[UVA488]Triangle Wave

#include<cstdio> int main() { int T; while(scanf("%d",&T)!=EOF){ for(int l=0;l<T;l++) { int a,f; scanf("%d%d",&a,&f); if(l) printf("\n"); for(int k=0;k<f;k++) { if(k) printf("\n"); for(int i=1;i<=a;i++) { for(int j=1;j<=i;j++) printf("%d",i); printf("\n"); } for(int i=a-1;i>=1;i--) { for(int j=1;j<=i;j++) printf("%d",i); printf("\n"); } } } } return 0; }

建立 python 環境(windows 8)

圖片
   本篇我要介紹怎用sublime text3 編譯 python 2,給不想使用IDLE的人,以下我會用windows       8 做示範。    --------------------------------------------------------------------------------------------------------------     首先下載python 2 並安裝     連結  https://www.python.org/downloads/        接著設定系統變數    控制台 > 系統及安全性 > 系統 >變更設定 > 進階 >環境變數 > path > 編輯 >    加入 以下這行     C:\python27;C:\python27\Scripts                    接著開啟sublime text 3 建立一個 python 檔案  hello.py 存在桌面                 開啟 命令提示字元 (在搜尋 輸入 cmd開啟)     輸入 cd desktop  (切換到桌面)     輸入python Hello.py (編譯執行 Hello.py檔案)               大概就是這樣了喔~     希望有幫到 不想使用 IDLE 的大家!!!     

[ZJ]b428: 凱薩加密

題目: http://zerojudge.tw/ShowProblem?problemid=b428 ========================================================== #include<cstdio> #define maxn 1050 int main(void) { char a[maxn],b[maxn]; while(scanf("%s%s",&a,&b)!=EOF) { int ans = b[0] - a[0]; printf("%d\n",ans >= 0? ans : ans + 26); } return 0; }

[ZJ]a003: 兩光法師占卜術

題目: http://zerojudge.tw/ShowProblem?problemid=a003 ========================================================= #include<cstdio> int main(void) { int M,D,S; while(scanf("%d %d",&M,&D)!=EOF){ S=(M*2+D)%3; if(S==0) printf("普通\n"); else if(S==1) printf("吉\n"); else if(S==2) printf("大吉\n"); } return 0; }

[ZJa002]簡易加法

題目: http://zerojudge.tw/ShowProblem?problemid=a002 ================================================= #include<cstdio> int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b); return 0; }

[ZJa111][UVA12149] Feynman

題目: http://zerojudge.tw/ShowProblem?problemid=a111 ============================================================ #include<cstdio> int main() {     int a;     while (scanf("%d",&a)!=EOF&& a !=0 ){           int ans =0 ;           for (int i=1 ;i<=a;i++)               ans +=i*i ;           printf("%d \n",ans);     }     return 0; }

[ZJa012][UVA10055] Hashmat the Brave Warrior

題目: http://zerojudge.tw/ShowProblem?problemid=a012 ====================================================== #include<stdio.h> int main() { long long int a,b,z; while(scanf("%lld%lld",&a,&b)!=EOF) { z=b-a; if(z<0) z=-z; printf("%lld\n",z); } return 0; }

[ZJ]d786: 三、平均值

題目: http://zerojudge.tw/ShowProblem?problemid=d786 ================================================== #include<stdio.h> #include<stdlib.h> #define N 150 int main() { int T; while(scanf("%d",&T)!=EOF) { int a=0; while(a<T) { int n=0,x[N]={0}; double avg=0.0; a++; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&x[i]); avg+=x[i]; } printf("%.2lf\n",avg/n); } } return 0; }

[ZJ]d887: 1.山脈種類(chain)

題目: http://zerojudge.tw/ShowProblem?problemid=d887 ======================================================== #include<cstdio> #include<cstring> int main(void) { int n; while(scanf("%d",&n)!=EOF) { long long int DP[30][30]; memset(DP,0,sizeof(DP)); DP[0][1] = 1; for(int i=1;i<=n+1;i++) { for(int j=i;j<=n+1;j++) DP[i][j] = DP[i-1][j] + DP[i][j-1]; } printf("%lld\n",DP[n+1][n+1]); } return 0; }

[ZJ]b557: 直角三角形

題目: http://zerojudge.tw/ShowProblem?problemid=b557 ================================================================ #include<iostream> #include<cmath> #include<algorithm> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { int n,x[110]={0},count = 0; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&x[i]); sort(x,x+n); for(int i=0;i<n-2;i++) { for(int j=i+1;j<n-1;j++) { for(int k=j+1;k<n;k++) { if(pow(x[k],2) == pow(x[i],2) + pow(x[j],2)) count++; } } } printf("%d\n",count); } return 0; }

[ZJd189][UVA11150] Cola

題目: http://zerojudge.tw/ShowProblem?problemid=d189 ==================================================================== #include<cstdio> int main() {    int a;    while (scanf("%d",&a)!=EOF){          int ans = a;                          while (a>=3){                ans +=a/3 ;                a = a/3 + a %3 ;          }          if (a == 2)             ans++;          printf("%d\n",ans);    }    return 0; }

[ZJd226][UVA10071] Back to High School Physics

題目: http://zerojudge.tw/ShowProblem?problemid=d226 ================================================================ #include<cstdio> int main(void) { int v, t; while(scanf("%d%d",&v,&t)!=EOF) { printf("%d\n",v*t*2); } return 0; }

[ZJd260][UVA11455] Behold my quadrangle

題目: http://zerojudge.tw/ShowProblem?problemid=d260 ==================================================================== #include<cstdio> #include<cmath> typedef long long int LL; int main() { int T; scanf("%d",&T); while(T--) { LL a,b,c,d; scanf("%lld%lld%lld%lld",&a,&b,&c,&d); if(a == b && b == c && c == d) printf("square\n"); else if(a == c && b == d || a == b && c == d || a == d && b == c) printf("rectangle\n"); else if(((a+b+c)<=d)||((a+b+d)<=c)||((a+c+d)<=b)||((b+c+d)<=a)) printf("banana\n"); else printf("quadrangle\n"); } return 0; }

[ZJd660][UVA11764] Jumping Mario

題目: http://zerojudge.tw/ShowProblem?problemid=d660 ========================================================= #include<bits/stdc++.h> using namespace std; int main() { int T,i = 0; scanf("%d",&T); while(T--) { int n,a, highsum = 0, lowsum = 0, odd = 0; scanf("%d",&n); scanf("%d",&a); odd = a; while(n-->1) { scanf("%d",&a); if(a > odd) highsum++; if(a < odd) lowsum++; odd = a; } i++; printf("Case %d: %d %d\n",i,highsum,lowsum); } return 0; }

[ZJd669][UVA11677] Alarm Clock

題目: http://zerojudge.tw/ShowProblem?problemid=d669 ===================================================================== #include<cstdio> int main(void) { int h1,m1,h2,m2; while(scanf("%d%d%d%d",&h1,&m1,&h2,&m2)!=EOF) { int z=0; if(h1==0 && m1==0 && h2==0 && m2==0)break; if(h2<h1 || h1==h2 && m2<m1) h2+=24; z=(h2-h1)*60-m1+m2; printf("%d\n",z); } return 0; }

[ZJ]a227: 三龍杯 -> 河內之塔

題目: http://zerojudge.tw/ShowProblem?problemid=a227 ================================================================== #include<stdio.h> int tower(int n,char a,char b,char c) { if(n>0) { tower(n-1,a,c,b); printf("Move ring %d from %c to %c\n",n,a,c); tower(n-1,b,a,c); } } int main(void) { int n; while(scanf("%d",&n)!=EOF) { tower(n,'A','B','C'); } return 0; }

[ZJ]a273: 小朋友下樓梯

題目: http://zerojudge.tw/ShowProblem?problemid=a273 ==================================================================== #include<stdio.h> int main() { int a, b; while(scanf("%d%d",&a,&b)!=EOF) { if(a == b) printf("Ok!\n"); else printf("%s\n",(b !=0 && a % b ==0 ?"Ok!" :"Impossib1e!" )); } return 0; }

[ZJ]a858: 數三角形

題目: http://zerojudge.tw/ShowProblem?problemid=a858 ============================================================ #include<bits/stdc++.h> using namespace std; int main() { int n;     while(scanf("%d", &n)!=EOF) {     int ans = n*(n-1)*(n-2)/2/3;     int temp = 0;     for(int i = 0; i < n; i++)     {         int r = 0, b = 0;        for(int j = 0; j < n; j++)         {             int p;             scanf("%d", &p);             if( p == 1 ) r++;             if( p == 2 ) b++;         }         temp += r*b;     }     ans -= temp/2;     printf("%d\n", ans); } return 0; }

[ZJ]b676: 63萬勞工苦輪班不像人像機器

題目: http://zerojudge.tw/ShowProblem?problemid=b676 ================================================================ #include<cstdio> int main(void) { int n; while(scanf("%d",&n)!=EOF) { if(n % 5 == 0) printf("U\n"); else if(n % 5 == 1) printf("G\n"); else if(n % 5 == 2) printf("Y\n"); else if(n % 5 == 3) printf("T\n"); else printf("I\n"); } return 0; }

[ZJ]d180: 拿硬幣

題目: http://zerojudge.tw/ShowProblem?problemid=d180 ================================================= #include<cstdio> int main() {     int a, sum0 =0, sum1 =0, b;     scanf("%d",&a);     while(a--){           scanf("%d",&b);           (a % 2 == 0? sum0 += b : sum1 += b) ;     }     printf("%s\n",(sum0 >sum1 ? "right" :"left" ));     return 0 ; }

[ZJ]d290: 完全数

題目: http://zerojudge.tw/ShowProblem?problemid=d290 ======================================================== #include<cstdio> int main() {     printf("33550336\n"); return 0; }

[ZJ]d294: 算算算....Easy

題目: http://zerojudge.tw/ShowProblem?problemid=d294 ===================================================== #include<bits/stdc++.h> using namespace std; typedef long long int LL; int main() { LL n,m; while(scanf("%lld%lld",&n,&m)!=EOF) { printf("%lld\n",((n*(n+1))*(m*(m+1)))/4); } return 0; }

[ZJ]d579: 兩條線

題目: http://zerojudge.tw/ShowProblem?problemid=d579 ============================================================= #include<cstdio> int main() { double a; while(scanf("%lf",&a)!=EOF) printf("|%.4lf|=%.4lf\n",a,a>0?a:-a); return 0; }

[ZJ]d581: 三條線

題目: http://zerojudge.tw/ShowProblem?problemid=d581 ========================================================= #include <iostream> using namespace std; int main() {     long long int a;     while (cin >>a ){           while (a--){                 cout <<"=_=|||" <<endl ;           }     } }

[ZJ]d807: 方方

題目: http://zerojudge.tw/ShowProblem?problemid=d807 ============================================================ #include<cstdio> int main() {     long long int a,b,ans;     while (scanf("%lld%lld",&a,&b)!=EOF) {     for (int i=1;i<=a && i<=b;i++) {         if (a%i ==0 && b%i==0)             ans=i;         }     printf("%lld\n",ans);     } return 0; }

[ZJ]d236: 畢氏的定理

題目: http://zerojudge.tw/ShowProblem?problemid=d236 =============================================================== #include<cstdio> int main(){ printf("31875000\n"); return 0; }

[ZJ]d238: "<<"運算子真好用

題目: http://zerojudge.tw/ShowProblem?problemid=d238 ============================================================= #include<cstdio> int main(void) { printf("1366\n"); return 0; }

[ZJ]d237: 質數合

題目: http://zerojudge.tw/ShowProblem?problemid=d237 ==================================================== #include<stdio.h> int main() { printf("142913828922\n"); }

[ZJa132][UVA10931] Parity

題目: http://zerojudge.tw/ShowProblem?problemid=a132 ----------------------------------------------------------------------------------------------------------------- #include<cstdio> #include<cstdlib> #include<cstring> #define N 1000 int stack[N]; int top=-1; void push(int); int pop(void); void printStack(void); int main(void) { int x,y; while(scanf("%d",&x)!=EOF && x != 0) { while(x>=0) { y=x%2; push(y); x=x/2; if(x==0) break; } int ans = 0; for(int i=0;i<=top;i++) { if(stack[i] == 1) ans++; } char s[1000]={}; int j = top; for(int i=0;i<=top;i++) { s[i] = stack[j] + 48; j--; } printf("The parity of %s is %d (mod 2).\n",s,ans); while(top!=-1)             top=-1; } return 0; } void push(int y) { stack[++top]=y; } int pop(void) { return stack[top--]; }

[ZJc079][UVA10346] Peter's Smokes

題目: http://zerojudge.tw/ShowProblem?problemid=c079 ==================================================== #include<cstdio> int main() {     int a, b;     while (scanf("%d%d",&a,&b)!=EOF){           int sum = a;           while (a >= b){                 sum += a / b ;                 a = a / b + a % b;           }           printf("%d\n",sum);     }     return 0; }

[CF]A. Gabriel and Caterpillar

題目: http://codeforces.com/problemset/problem/652/A --------------------------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; const int n = 4e5 + 5; int main() {   int h1, h2;   int a, b;   scanf("%d%d",&h1,&h2);   scanf("%d%d",&a,&b);   h1 += 8 * a;   if(h1 >= h2){     printf("0\n");     return 0;   }   h1 -= 12 * b;   if(a <= b){     printf("-1\n");     return 0;   }   int day = 1;   for(int i=0;i<n;i++){     h1 += 12 * a;     if(h1 >= h2){       printf("%d\n",day);       return 0;     }     h1 -= 12 * b;     day++;   }   printf("-1\n");   return 0; }

[TIOJ]1011 . Edit Distance In Numbers

題目: http://tioj.ck.tp.edu.tw/problems/1011 -------------------------------------------------------------------------------------------- #include<cstdio> int main() { unsigned int a,b; while(scanf("%u%u",&a,&b)!=EOF) { unsigned int ans = 0; while(a != b) { if(a < b) { unsigned int t = a; a = b; b = t; } a /= 2; ans++; } printf("%u\n",ans); } return 0; }

[ZJ]b759: 我明明就有說過= =

題目: http://zerojudge.tw/ShowProblem?problemid=b759 ---------------------------------------------------------------------------------------------- #include<cstdio> #include<cstring> #define maxn 1000+10 int main(void) { char s[maxn]; memset(s,' ',sizeof(s)); while(scanf("%s",&s)!=EOF) { int len = strlen(s), a = 0; printf("%s\n",s); for(int i=1;i<len;i++) { a = i; for(int j=i;j<len;j++) { printf("%c",s[j]); if(j == len - 1) { for(int z=0;z<a;z++) printf("%c",s[z]); } } printf("\n"); } } return 0; }

[ZJ]a417: 螺旋矩陣

題目: http://zerojudge.tw/ShowProblem?problemid=a417 ---------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> #define maxn 105 using namespace std; int main(void) { int T,a[maxn][maxn]; scanf("%d",&T); while(T --> 0) { int n,m,x,y,tot = 0; scanf("%d%d",&n,&m); memset(a,0,sizeof(a)); tot = a[x=0][y=0] = 1; if(m == 1) { while(tot < n*n) { while(y+1<n && !a[x][y+1]) a[x][++y] = ++tot; while(x+1<n && !a[x+1][y]) a[++x][y] = ++tot; while(y-1>=0 && !a[x][y-1]) a[x][--y] = ++tot; while(x-1>=0 && !a[x-1][y]) a[--x][y] = ++tot; } } else { while(tot < n*n) { while(x+1<n && !a[x+1][y]) a[++x][y] = ++tot; while(y+1<n && !a[x][y+1]) a[x][++y] = ++tot; while(x-1>=0 && !a[x-1][y])

[ZJ]a248: 新手訓練 ~ 陣列應用

題目: http://zerojudge.tw/ShowProblem?problemid=a248 -------------------------------------------------------------------------------------------- #include<cstdio> int main() {     int a, b, N;     while(scanf("%d %d %d", &a, &b, &N) == 3) {         printf("%d.", a/b), a %= b;         while(N--)         {         a *= 10; printf("%c", a/b+'0'); a %= b; }         puts("");     }     return 0; }

[ZJ]a244: 新手訓練 ~ for + if

題目: http://zerojudge.tw/ShowProblem?problemid=a244 ------------------------------------------------------------------------------------- #include<cstdio> int main(void) { int n,i=0,a; long long int b,c; scanf("%d",&n); while(i<n) { scanf("%d%lld%lld",&a,&b,&c); if(a==1) printf("%lld",b+c); else if(a==2) printf("%lld",b-c); else if(a==3) printf("%lld",b*c); else printf("%lld",b/c); printf("\n"); i++; } return 0; }

[ZJ]a225: 明明愛排列

題目: http://zerojudge.tw/ShowProblem?problemid=a225 -------------------------------------------------------------------------------------------------------- #include<cstdio> #include<cstdlib> #define N 1000+50 int main(void) { int n; while(scanf("%d",&n)!=EOF) { int x[N]={0}; int i,j,z=0,z2=0; for(i=0;i<n;i++) scanf("%d",&x[i]); for(i=n-1;i>0;i--) { for(j=0;j<i;j++) { if(x[j]%10 > x[j+1]%10) { z=x[j]; x[j]=x[j+1]; x[j+1]=z; } else if(x[j]%10==x[j+1]%10 && x[j]<x[j+1]) { z2=x[j]; x[j]=x[j+1]; x[j+1]=z2; } } } for(int i=0;i<n;i++) printf("%d ",x[i]); printf("\n"); } return 0; }

[ZJ]a216: 數數愛明明

題目: http://zerojudge.tw/ShowProblem?problemid=a216 ----------------------------------------------------------------------------------------------- #include<cstdio> typedef long long int LL; LL f (int n ) {            return n + n*(n-1) /2 ; } LL g (int n ) {          if (n==1 ){         return 1;      }        return f(n) + g(n-1) ; } int main(void) {     LL n;     while(scanf("%d",&n)!=EOF) { printf("%lld %lld\n",f(n),g(n));     } return 0; }

[ZJ]a148. You Cannot Pass?!

題目: http://zerojudge.tw/ShowProblem?problemid=a148 ------------------------------------------------------------------------------ #include<cstdio> int main() {     int n;     while(scanf("%d",&n)!=EOF) {     long long int a,sum =0 ;         for (int i=0 ;i<n;i++) scanf("%d",&a),sum += a;         printf("%s\n",(sum <=n *59 ?"yes" :"no" ));     }     return 0; }

[ZJ]a215: 明明愛數數

題目: http://zerojudge.tw/ShowProblem?problemid=a215 ----------------------------------------------------------------------------------------------- #include<cstdio> int main() { int a, b; while(scanf("%d%d",&a,&b)!=EOF) { int ans = 1; for(int i=0;i+a<=b;i++) ans++,b -= (a + i); printf("%d\n",ans); } return 0; }

[ZJ]b515: 摩斯電碼-商競103

題目: http://zerojudge.tw/ShowProblem?problemid=b515 ----------------------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std ; string s[]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."} ; map<string,char> a ; string str; int main(){     for (int i=0;i<26;i++)         a[s[i]] = 'A' + i ;     int T;     scanf("%d",&T);     getline(cin,str) ;     while (T-- && getline(cin,str) ){         stringstream ss;         ss <<str;         string cha;         while (ss>

[ZJ]b520: 樂透-商競103

題目: #include<bits/stdc++.h> using namespace std; int getin() { int re = 0; char c; while (!isdigit(c = getchar()));   do {         re=10*re+c-'0';     }while (isdigit(c = getchar())) ;         return re; } int main() { int T; scanf("%d",&T); while(T--) { int a[7] = {0}, b[7] = {0}; for(int i=0;i<5;i++) a[i] = getin(); for(int i=0;i<5;i++) b[i] = getin(); sort(a,a+5); sort(b,b+5); int sum = 0; for(int i=0;i<5;i++) { for(int j=0;j<5;j++) { if(a[i] == b[j]) sum++; } } printf("%d\n",sum); } return 0; }

[ZJ]a647: 投資專家

題目: http://zerojudge.tw/ShowProblem?problemid=a647 -------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std; #define maxn 1e-9 int main() { int T;     scanf("%d",&T);     while(T--)     {         long double m, p;         scanf("%Lf %Lf", &m, &p);         long double ans = (p/m-1)*100;         if( ans > -maxn ) printf("%.2Lf%% ", ans+maxn);         else printf("%.2Lf%% ", ans-maxn);         if( p/m-1 > 0.1-maxn || p/m-1 < -0.07+maxn) puts("dispose");         else puts("keep");     } }

[ZJ]d732: 二分搜尋法

題目: http://zerojudge.tw/ShowProblem?problemid=d732 --------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std; int binsrch(int num[], int len, int target){ int lower = 0; int upper = len-1; int mid=0; while(lower <= upper){ mid = (lower + upper) / 2; if(target > num[mid]) lower = mid + 1; else if(target < num[mid]) upper = mid - 1; else return mid + 1; } return 0; } int main(){ int len,query,i; cin>>len>>query; int num[len]; int target[query]; int ans[query]; for(i=0;i<len;i++) cin>>num[i]; for(i=0;i<query;i++){ cin>>target[i]; ans[i] = binsrch(num,len,target[i]); } for(i=0;i<query;i++) cout<<ans[i]<<"\n"; return 0; }

[ZJ]a149: 乘乘樂

題目: http://zerojudge.tw/ShowProblem?problemid=a149 ---------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 100 int main() { int n,T; char x2[N]={' '}; int x[N]={0}; scanf("%d",&T); while(scanf("%s",&x2)!=EOF) { n=strlen(x2); for(int i=0;i<n;i++) x[i]=x2[i]-48; long long int ans=1; for(int i=0;i<n;i++) { ans*=x[i]; } printf("%lld\n",ans); } return 0; }

[ZJ]a147: Print it all

題目: http://zerojudge.tw/ShowProblem?problemid=a147 -------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int main(void) {     int n,i;         while(scanf("%d",&n)!=EOF)     {     for(i=1;i<n;i++)     {                      if(i>0 && i%7!=0)                      {                             printf("%d ",i);                      }     }     printf("\n"); } }

[ZJ]a104: 排序

題目: http://zerojudge.tw/ShowProblem?problemid=a104 ------------------------------------------------------------------------------------------ #include<stdio.h> #include<stdlib.h> int main() {     int in0;     while (scanf("%d",&in0)!=EOF){           int in[in0];           for (int i=0;i<in0;i++)               scanf("%d",&in[i]);           for (int i=0;i<in0;i++)               for (int i1=0;i1<in0;i1++)                   if (in[i]<in[i1]){                      int a;                      a=in[i];                      in[i]=in[i1];                      in[i1]=a;                   }           for (int i=0;i<in0;i++)               printf("%d ",in[i]);           printf("\n");     }     return 0; }

[ZJ]a065: 提款卡密碼

題目: http://zerojudge.tw/ShowProblem?problemid=a065 --------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int main() { char x[7]={' '}; while(scanf("%s",&x)!=EOF) { for(int i=0;i<7-1;i++) { printf("%d",abs(x[i+1]-x[i])); } printf("\n"); } return 0;  }

[ZJ]a095: 麥哲倫的陰謀

題目: http://zerojudge.tw/ShowProblem?problemid=a095 ------------------------------------------------------------------------------------------------------- #include<cstdio> int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) { if(n == m) printf("%d\n",m); else printf("%d\n",m+1); } return 0; }

[ZJ]a053: Sagit's 計分程式

題目: http://zerojudge.tw/ShowProblem?problemid=a053 ------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int main() {     int in0 ,out ;     while (scanf("%d",&in0)!=EOF){           if (in0 >=40)              out=100 ;           else if (in0 >20)                out =80 +(in0 -20) *1 ;           else if (in0 >10)                out =60 +(in0 -10) *2 ;           else                out =in0 *6 ;           printf("%d \n",out);     }     return 0; }

[ZJ]a044: 空間切割

題目: http://zerojudge.tw/ShowProblem?problemid=a044 ---------------------------------------------------------------------------------------------------- #include<cstdio> int main(void) { int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",(n*(n*n+5))/6+1); } return 0; }

[ZJ]a042: 平面圓形切割

題目: http://zerojudge.tw/ShowProblem?problemid=a042 --------------------------------------------------------------------------------------------------------- #include<stdio.h> int main(void) { int n; while(scanf("%d",&n)!=EOF) { n=n*(n-1)+2; printf("%d\n",n); } return 0; }

[ZJ]b761: 搶30

題目: http://zerojudge.tw/ShowProblem?problemid=b761 ----------------------------------------------------------------------------------------------------------------- #include<cstdio> int main() { int n; while(scanf("%d",&n)!=EOF) printf("%s\n",(n%4!=0)?"fat":"egg"); return 0; }

[ZJ]a034: 二進位制轉換

題目: http://zerojudge.tw/ShowProblem?problemid=a034 ------------------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #define N 100 int stack[N]; int top=-1; void push(int); int pop(void); void printStack(void); int main(void) { int x,y; while(scanf("%d",&x)!=EOF){ while(x>=0) { y=x%2; push(y); x=x/2; if(x==0) break; } printStack(); printf("\n"); while(top!=-1) {                   top=-1;     } } } void push(int y) { stack[++top]=y; } int pop(void) { return stack[top--]; } void printStack(void) { int i; for(i=top;i>=0;i--) { printf("%d",stack[i]); } }

[ZJ]a024. 最大公因數(GCD)

題目: http://zerojudge.tw/ShowProblem?problemid=a024 ----------------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> int GCD(int a,int b) { int c; c=a%b; if(c==0) return b; else return GCD(b,c); } int main(void) { int a,b; while(scanf("%d%d",&a,&b)!=EOF) { printf("%d",GCD(a,b)); printf("\n"); } return 0; }

[ZJ]a022: 迴文

題目: http://zerojudge.tw/ShowProblem?problemid=a022 ------------------------------------------------------------------------------------------------------------------ #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 1100 int main(void) { int i,len;//len記字串長度 char str[N]; while(gets(str)){ len=strlen(str);//strlen計算字串長度 for(i=0;i<len/2;i++) { if(str[i]!=str[len-i-1]) { printf("no\n"); break; } } if(i>=len/2) printf("yes\n"); } return 0; }

[ZJ]a015: 矩陣的翻轉

題目: http://zerojudge.tw/ShowProblem?problemid=a015 -------------------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 100 int main(void) { int m,n,i,j; while(scanf("%d %d",&m,&n)!=EOF){ int A[N][N]; int B[N][N]; memset(A,0,sizeof(A)); memset(B,0,sizeof(B)); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&A[i][j]); } } for(i=0;i<m;i++) { for(j=0;j<n;j++) { B[j][i]=A[i][j]; } } for(i=0;i<n;i++) { for(j=0;j<m;j++) { printf("%d",B[i][j]); printf(" "); } printf("\n"); } printf("\n"); } return 0; }

[ZJ]a009: 解碼器

題目: http://zerojudge.tw/ShowProblem?problemid=a009 -------------------------------------------------------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<string.h> #define N 200 int main() { int n; char s[200]; memset(s,' ',sizeof(s)); while(gets(s)) { n=strlen(s); for(int i=0;i<n;i++) printf("%c",s[i]+'*'-'1'); printf("\n"); } return 0; }

[ZJ]a006. 一元二次方程式

題目: http://zerojudge.tw/ShowProblem?problemid=a006 -------------------------------------------------------------------------------------------------------------------- #include <iostream> #include <cmath> using namespace std; int main() {     int a, b, c;       while (cin >>a >>b >>c ){                   if (b*b -4*a*c <0)                        cout << "No real root";           else if (b*b -4*a*c ==0)                  cout <<"Two same roots x=" <<-b /(2*a) ;           else                                     cout << "Two different roots x1=" << (-b + sqrt(b*b-4*a*c)) / (2*a)                    << " , x2=" << (-b - sqrt(b*b-4*a*c)) / (2*a) ;                   cout <<endl ;             } return 0; }

[ZJ]a005: Eva 的回家作業

題目: http://zerojudge.tw/ShowProblem?problemid=a005 ------------------------------------------------------------------------------------------------------------------ #include<stdio.h> #include<stdlib.h> int main(void) { int N,a,b,c,d,r,e,s; while(scanf("%d",&N)!=EOF){ for(int i=1;i<=N;i++) { scanf("%d %d %d %d",&a,&b,&c,&d); if(b - a == c - b) { s = b - a; e = a + 4 * s; printf("%d %d %d %d %d",a,b,c,d,e); } else if(b / a == c / b) { r = b / a; e = a * r * r * r * r; printf("%d %d %d %d %d",a,b,c,d,e); } printf("\n"); } } return 0; }

[ZJd097][UVA10038] Jolly Jumpers

題目: http://zerojudge.tw/ShowProblem?problemid=d097 ----------------------------------------------------------------------------------------------------------------------- #include<cstdio> #define maxn 3000+1 int main() { int n; while(scanf("%d",&n)!=EOF) { int a[maxn] = {0}, y = 0, x = 0, ans = 0, z = 0; scanf("%d",&x); for(int i=1;i<n;i++) { scanf("%d",&y); ans = x-y>=0?x-y:y-x; a[ans] = 1; x = y; } for(int i=1;i<=n-1;i++) { if(!a[i]) { z = 1; break; } } printf("%s\n",!z ? "Jolly" :"Not jolly"); } return 0; }

[ZJd123][UVA11063 ] B2-Sequence

題目: http://zerojudge.tw/ShowProblem?problemid=d123 -------------------------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std; int main() { int b[100],n,T = 1; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) scanf("%d",&b[i]); int a[20001]={0}, z = 1; for(int i=0;i<n;i++) { for(int j=i;j<n;j++) { if(a[b[i]+b[j]] !=0) { z = 0; break; } if(a[b[i]+b[j]] == 0) a[b[i]+b[j]]++; } if(z == 0) break; } printf("Case #%d: It is %s.\n",T++,(z)?"a B2-Sequence":"not a B2-Sequence"); } return 0; }