發表文章

目前顯示的是 4月, 2016的文章

[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--]; }