發表文章

目前顯示的是有「UVA」標籤的文章

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

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

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

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

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

[ZJc084][UVA275] - Expanding Fractions

題目: http://zerojudge.tw/ShowProblem?problemid=c084 ------------------------------------------------------------------------------------------------------------------ #include<bits/stdc++.h> #define maxn 1000+1 using namespace std; int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF && a || b) { int x = 0,s1[maxn]={0},s2[maxn]={0}, len = 0, z = 0; s2[0] = a; while(1) { z = 0; x++; s1[x] = a * 10 / b; a = (a * 10) % b; s2[x] = a; if(!a) { len = -1; break; } for(int i=0;i<x;i++) { if(s2[x] == s2[i]) { z = 1; len = x - i; break; } } if(z) break; } printf("."); for(int i=1;i<=x;i++) { printf("%d",s1[i]); if((i + 1) % 50 == 0) printf("\n"); } printf("\n"); if(len > 0) printf("The last %d digits repeat forever.\n",len); if(len == -1) ...

[ZJd044][UVA640] Self Numbers

題目: http://zerojudge.tw/ShowProblem?problemid=d044 ----------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> #define maxn 1000000+1 using namespace std; int a[maxn] = {0}; int main() { int x = 0, j = 0; for(int i=1;i<maxn;i++) { j = i; if(a[j] == 0) { while(1) { x = j; while(j > 0) { x += j % 10; j = j / 10; } if(x < maxn && a[x] == 0) { a[x] = 1; j = x; } else break; } } } for(int i=1;i<maxn;i++) if(a[i] == 0) printf("%d\n",i); return 0;  }

[ZJc061][UVA530] - Binomial Showdown

題目: http://zerojudge.tw/ShowProblem?problemid=c061 -------------------------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> using namespace std; typedef long long int LL; int main() { LL n,m; while(scanf("%lld%lld",&n,&m)!=EOF && n || m) { if(2 * m > n) m = n - m; LL ans = 1; for(int i=1;i<=m;i++) ans = ans * (n - m  + i) / (i); //乘一個數就除一個數 printf("%lld\n",ans); } return 0; }

[ZJa130][UVA12015] Google is Feeling Lucky

題目: http://zerojudge.tw/ShowProblem?problemid=a130 -------------------------------------------------------------------------------------------------- #include<bits/stdc++.h> #define maxn 100+1 using namespace std; int main() { int T,j=1; scanf("%d",&T); while(T--) { char s[15][maxn]; int r[15] = {0},maxi = -1; for(int i=0;i<10;i++) { scanf("%s %d",s[i],&r[i]); maxi = max(maxi,r[i]); } printf("Case #%d:\n",j++); for(int i=0;i<10;i++) { if(maxi == r[i]) printf("%s\n",s[i]); } } return 0; }

[ZJa135][UVA12250] Language Detection

題目: http://zerojudge.tw/ShowProblem?problemid=a135 -------------------------------------------------------------------------------------------------------------------------- #include<iostream> using namespace std; string s[] = { "ENGLISH","SPANISH","GERMAN","FRENCH","ITALIAN","RUSSIAN" }; string he[] = { "HELLO","HOLA","HALLO","BONJOUR","CIAO","ZDRAVSTVUJTE" }; int main() {   int T = 0;   string a;   while( cin >> a && a != "#" ) {     int z = 0;     for(int i=0;i<6;i++) {       if(he[i] == a) {         printf("Case %d: %s\n", ++T,s[i].c_str());         z = 1;         break;       }     }     if(!z)       printf("Case %d: UNKNOWN\n", ++T);   }   return 0; }

[ZJd658[UVA11636] Hello World!

題目: http://zerojudge.tw/ShowProblem?problemid=d658 --------------------------------------------------------------------------------------------------- #include<cstdio> #include<cmath> int main() { int n,T=1; while(scanf("%d",&n) == 1 && n > 0) printf("Case %d: %d\n",T++,(int)ceil(log2(n))); return 0; }

[ZJd235][UVA10929] You can say 11

題目: http://zerojudge.tw/ShowProblem?problemid=d235 ------------------------------------------------------------------------------------------------------------ #include<bits/stdc++.h> using namespace std; int main() { string s; while(cin >> s) { if(s == "0")break; int a = 0, b = 0; for(int i=0;i<s.length();i++) { if(i % 2 == 0) a = a + (s[i] - '0'); else b = b + (s[i] - '0'); } if((a - b) % 11 == 0) cout << s <<" is a multiple of 11.\n"; else cout << s <<" is not a multiple of 11.\n"; } return 0; }