Open 15j5141 opened 1 year ago
#include<stdio.h> int main(){ int i,j; for(i=1;i<10;i++){ for(j=1;j<10;j++){ printf("%dx%d=%d\n",i,j,i*j); } } return 0; } #include<stdio.h> int main(void){ int n; int a,b; while(scanf("%d %d",&a,&b) != EOF){ n = a + b; int dig = 0; while(n!=0){ n=n/10; dig++; } printf("%d\n",dig); } return 0; } #include<stdio.h> void swapc(int*, int*); int main(){ int a,b,c,n,i; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d %d %d",&a,&b,&c); swapc(&a,&c); swapc(&b,&c); if(a*a+b*b == c*c){ printf("YES\n"); } else { printf("NO\n"); } } return 0; } void swapc(int *x, int *c){ int temp; if(*x>*c){ temp = *x; *x = *c; *c = temp; } } #include <stdio.h> #include <math.h> int main(void){ double a,b,c,d,e,f,aa,bb,cc,x,y,bai; while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF){ bai=d/a; aa=a*bai; bb=b*bai; cc=c*bai; y=(f-cc)/(e-bb); x=(c-b*y)/a; printf("%.3f %.3f\n",x,y); } } #include<stdio.h> long int LCM(long int, long int); void swap(long int*, long int*); int main(){ long int a,b; long int lcm,gcd; while(scanf("%ld %ld",&a,&b) != EOF){ swap(&a,&b); lcm = LCM(a,b); gcd = a/lcm*b; printf("%ld %ld\n",lcm,gcd); } return 0; } long int LCM(long int a, long int b){ int r; if (b==0){ return a; } else { r = a % b; return LCM(b,r); } } void swap(long int *x, long int *y){ long int temp; if(*x<*y){ temp = *x; *x = *y; *y = temp; } } #include <stdio.h> #include <string.h> int main(void){ int len,i; char str[100]; scanf("%s",str); len=strlen(str); for(i=len-1;i>=0;i--){ printf("%c",str[i]); } printf("\n"); } #include<stdio.h> int main(){ int n,i,a=100000; scanf("%d",&n); for(i=0;i<n;i++){ a=a*1.05; if(a%1000>0) a=a/1000*1000+1000; } printf("%d\n",a); return 0; } #include <stdio.h> #include <math.h> int main(void){ int a,b,c,d,n; while(scanf("%d",&n)!=EOF){ int count=0; for(a=0;a<=9;a++){ for(b=0;b<=9;b++){ for(c=0;c<=9;c++){ for(d=0;d<=9;d++){ if(a+b+c+d==n){ count++; } } } } } printf("%d\n",count); } } #include<stdio.h> #include<math.h> #include<stdbool.h> static int count = 0; static int prime[500000] = {2,3}; static bool primebool[500000] = {true,true}; int primesearch(int); void primecount(int,int); void reset(); int main(){ int n; while(scanf("%d", &n) != EOF){ if (n>1){ primecount(0,n); printf("%d\n", count); reset(); } else{ printf("0\n"); } } return 0; } void primecount(int i,int n){ if (!primebool[i]){ prime[i] = primesearch(prime[i-1]+2); primebool[i] = true; } if (prime[i]<=n){ count++; primecount(i+1,n); } } int primesearch(int x){ int i,sq; sq = (int)sqrt(x); for(i=3;i<=sq;i=i+2){ if(x%i==0){ return primesearch(x+2); } } return x; } void reset(){ count = 0; } #include <stdio.h> #include <math.h> int main(void) { int n; double x, y, x1, y1, x2, y2, x3, y3, x12, y12, z12, x23, y23, z23, r; scanf("%d", &n); while (n--) { scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3); x12 = 2 * (x2 - x1); y12 = 2 * (y2 - y1); z12 = x1*x1 - x2*x2 + y1*y1 - y2*y2; x23 = 2 * (x3 - x2); y23 = 2 * (y3 - y2); z23 = x2*x2 - x3*x3 + y2*y2 - y3*y3; x = (y12*z23 - y23*z12) / (x12*y23 - x23*y12); y = (z12*x23 - z23*x12) / (x12*y23 - x23*y12); r = hypot(x1 - x, y1 - y); printf("%.3lf %.3lf %.3lf\n", x, y, r); } return 0; } #include <stdio.h> int main(void){ int temp[31],temp1; int i,w,n,a,b; for(i=1;i<=30;i++) temp[i]=i; scanf("%d %d",&w,&n); for(i=0;i<n;i++){ scanf("%d,%d",&a,&b); temp1=temp[a]; temp[a]=temp[b]; temp[b]=temp1; } for(i=1;i<=w;i++){ printf("%d\n",temp[i]); } return(0); } #include <stdio.h> int main(void) { double x[3], y[3], xp, yp, cp[3]; int i, j; while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &xp, &yp ) == 8) { for (i = 0; i < 3; i++) { j = (i + 1) % 3; cp[i] = (x[j] - x[i]) * (yp - y[i]) - (y[j] - y[i]) * (xp - x[i]); } if ((cp[0] > 0 && cp[1] > 0 && cp[2] > 0) || (cp[0] < 0 && cp[1] < 0 && cp[2] < 0)) { puts("YES"); } else { puts("NO"); } } return 0; } #include<stdio.h> int main(void){ int railroad[10]={}; int car; int i=0; while((scanf("%d",&car))!=EOF){ if(car==0){//出ていく i--; printf("%d\n",railroad[i]); }else{//入ってくる railroad[i]=car; i++; } } return 0; } #include <stdio.h> int main(void){ int i,a,b,c,d,e; while(scanf("%d", &a)!= EOF) { b=600/a; int sum=0; for(i=1;i<b;i++){ e=i*a; d=e*e; c=a*d; sum+=c; } printf("%d\n",sum); if(a == 0) { break; } } return 0; } #include <stdio.h> #include <string.h> #define LEN 128 void convert(char charNum[], int intNum[]) { int i, j = 0; for (i = (int)strlen(charNum) - 1; i >= 0 ; i --) { intNum[j] = (int)charNum[i] - 48; j ++; } } int main(int argc, const char * argv[]) { int dataSet; int count = 1; scanf("%d", &dataSet); char firstNum[LEN], secondNum[LEN]; int fNum[LEN], sNum[LEN], sum[LEN]; int i, j, k, l; while (count <= dataSet) { count ++; while (scanf("%s", firstNum) != EOF) { break; } while (scanf("%s", secondNum) != EOF) { break; } if (strlen(firstNum) > 80 || strlen(secondNum) > 80) { printf("overflow\n"); continue; } for (i = 0; i < LEN; i ++) { fNum[i] = 0; sNum[i] = 0; sum[i] = 0; } convert(firstNum, fNum); convert(secondNum, sNum); for (i = 0; i < LEN; i ++) { sum[i] = fNum[i] + sNum[i]; } for (i = 0; i < LEN; i ++) { if (sum[i] >= 10) { sum[i] %= 10; sum[i + 1] += 1; } } k = 0; j = LEN - 1; while (j >= 0) { if (sum[j] == 0 && j != 0) { k ++; j --; } else { break; } } if (k < LEN - 80) { printf("overflow"); } else { for (l = LEN - k - 1; l >= 0; l --) { printf("%d", sum[l]); } } printf("\n"); } return 0; } #include<stdio.h> #include<math.h> int main(){ int d,r; double x=0,y=0; double rad=90; int a,b; while(scanf("%d,%d",&d,&r)!=EOF){ if(!d && !r)break; x+=d*cos(rad*M_PI/180); y+=d*sin(rad*M_PI/180); rad-=r; } a=(int)x; b=(int)y; printf("%d\n%d\n",a,b); return 0; } #include<stdio.h> int main(void){ int n; unsigned long long k=1; scanf("%d",&n); for(int i = n; i >= 1; i--){ k *= i; } printf("%lld\n",k); return 0; } #include <stdio.h> int main(){ char c; while(scanf("%c",&c)!=EOF){ printf("%c",toupper(c)); } return(0); } #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<math.h> int main() { int n; float a, b, c, d, e, f, g, h; scanf("%d", &n); for (int i = 0; i < n;i++){ int Bool = 0; scanf("%f %f %f %f %f %f %f %f", &a, &b, &c, &d, &e, &f, &g, &h); if (a == c || e == g) { if (a == c && e == g)Bool = 1; } else { if ((b - d) / (a - c) == (f - h) / (e - g))Bool = 1; } if (Bool == 1) { printf("YES\n"); } else { printf("NO\n"); } } } #include <stdio.h> #include <limits.h> int main(void) { int n, a, i, mx, acc; while (scanf("%d", &n) == 1 && n) { for (i = 0, mx = INT_MIN, acc = 0; i < n; i++) { scanf("%d", &a); acc += a; if (mx < acc) mx = acc; if (acc < 0) acc = 0; } printf("%d\n", mx); } return 0; } #include <stdio.h> #include <math.h> int main(void) { int N, i; double xa, ya, ra, xb, yb, rb, d; scanf("%d", &N); for (i = 0; i < N; i++) { scanf("%lf%lf%lf%lf%lf%lf", &xa, &ya, &ra, &xb, &yb, &rb); d = hypot(xb - xa, yb - ya); if (d > ra + rb) { puts("0"); } else if (d + rb < ra) { puts("2"); } else if (d + ra < rb) { puts("-2"); } else { puts("1"); } } return 0; } #include<stdio.h> int main(void){ float v; int n; while(scanf("%f",&v) != EOF){ n=(int)((4.9*v*v/9.8/9.8)+5)/5; n=n+1; printf("%d\n",n); } return 0; } /* * ID: 0025 * Problem: Hit and Blow */ #include <stdio.h> int main(void) { int a[4 + 1], b[4 + 1]; while (scanf("%d %d %d %d", a + 1, a + 2, a + 3, a + 4) != EOF) { scanf("%d %d %d %d", b + 1, b + 2, b + 3, b + 4); int hit = 0; int i; for (i = 1; i <=4; i++) if (a[i] == b[i]) { a[i] = b[i] = 0; hit++; } int blow = 0; int j; for (i = 1; i <=4; i++) { if (a[i] == 0) continue; for (j = 1; j <=4; j++) { if (b[j] == 0) continue; if (a[i] == b[j]) { a[i] = b[j] = 0; blow++; } } } printf("%d %d\n", hit, blow); } return 0; } #include <stdio.h> int main(void) { int x, y; int i, j; int n; int size; int god[10][10] = {}; int space; int mn; while (scanf("%d,%d,%d", &x, &y, &size) != EOF) { if (size == 1) { n = 1; god[x][y]++; for (i = 0; i < 2; i++) { if (x + n >= 0 && x + n < 10) { god[x + n][y]++; } if (y + n >= 0 && y + n < 10) { god[x][y + n]++; } n = -1; } } if (size == 2) { n = 1; god[x][y]++; for (i = 0; i < 2; i++) { if (x + n >= 0 && x + n < 10) { god[x + n][y]++; } if (y + n >= 0 && y + n < 10) { god[x][y + n]++; } if (x + n >= 0 && x + n < 10 && y + n >= 0 && y + n < 10) { god[x + n][y + n]++; } if (x + n >= 0 && x + n < 10 && y - n >= 0 && y - n < 10) { god[x + n][y - n]++; } n = -1; } } if (size == 3) { n = 1; god[x][y]++; for (i = 0; i < 2; i++) { if (x + n >= 0 && x + n < 10) { god[x + n][y]++; } if (y + n >= 0 && y + n < 10) { god[x][y + n]++; } if (x + n >= 0 && x + n < 10 && y + n >= 0 && y + n < 10) { god[x + n][y + n]++; } if (x + n >= 0 && x + n < 10 && y - n >= 0 && y - n < 10) { god[x + n][y - n]++; } if (x + n * 2 >= 0 && x + n * 2 < 10) { god[x + n * 2][y]++; } if (y + n * 2 >= 0 && y + n * 2 < 10) { god[x][y + n * 2]++; } n = -1; } } } space = 0; mn = 0; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { //printf("%3d", god[i][j]); if (god[i][j] == 0) { space++; } if (mn < god[i][j]) { mn = god[i][j]; } } //printf("\n"); } printf("%d\n%d\n", space, mn); return (0); } #include <stdio.h> int main(void){ int day,month,days; while(1){ scanf("%d %d",&month ,&day); if(month==0&&day==0){ break; }if(month==1){ days=day; }if(month==2){ days=31+day; }if(month==3){ days=31+29+day; }if(month==4){ days=31+29+31+day; }if(month==5){ days=31+29+31+30+day; }if(month==6){ days=31+29+31+30+31+day; }if(month==7){ days=31+29+31+30+31+30+day; }if(month==8){ days=31+29+31+30+31+30+31+day; }if(month==9){ days=31+29+31+30+31+30+31+31+day; }if(month==10){ days=31+29+31+30+31+30+31+31+30+day; }if(month==11){ days=31+29+31+30+31+30+31+31+30+31+day; }if(month==12){ days=31+29+31+30+31+30+31+31+30+31+30+day; }if(days%7==1){ printf("Thursday\n"); }if(days%7==2){ printf("Friday\n"); }if(days%7==3){ printf("Saturday\n"); }if(days%7==4){ printf("Sunday\n"); }if(days%7==5){ printf("Monday\n"); }if(days%7==6){ printf("Tuesday\n"); }if(days%7==0){ printf("Wednesday\n"); } } } #include <stdio.h> int main(void) { int bucket[101]; int i; int max; for (i = 0; i <= 100; i++){ bucket[i] = 0; } while (scanf("%d", &i) != EOF){ bucket[i]++; } max = 0; for (i = 0; i <= 100; i++){ if (bucket[i] > bucket[max]){ max = i; } } for (i = 0; i <= 100; i++){ if (bucket[i] == bucket[max]){ printf("%d\n", i); } } return (0); } #include<stdio.h> #include<string.h> #define MAX(x,y) (((x)>(y))?(x):(y)) int x=0,i=0,j,d[500],m=0,l=0; char s[500][36]; int main(){ memset(d,0,sizeof(d)); while(scanf("%s",s[x])!=EOF){ x++;j=0; for(i=0;i<x-1;i++){ if(strcmp(s[i],s[x-1])==0)d[i]++,j=1; m=MAX(m,d[i]); l=MAX(l,strlen(s[i])); } if(j==1)x--,j=0; } for(i=0;i<=x;i++)if(d[i]==m)printf("%s ",s[i]); for(i=0;i<=x;i++)if(strlen(s[i])==l)printf("%s\n",s[i]); return 0; } #include <stdio.h> int n, s, count = 0, digits[10]; // n 個の整数の和がsになる void dfs(int cur, int start) { // cur = 0 {} if(cur == n) { // cur = 1 {a} int sum = 0; // cur = 2 {a, b} for(int i = 0; i < n; i++) { sum += digits[i]; } if(sum == s) { count++; } return; } for(int i = start; i < 10; i++) { digits[cur] = i; // FIXME: 重複を避ける dfs(cur+1, i+1); } } int main(void){ while(scanf("%d %d",&n,&s)!= EOF){ if(n == 0 && s == 0){ break; } count = 0; dfs(0, 0); printf("%d\n", count); } return 0; } #include<stdio.h> #include<math.h> int main(void){ int n,b[100]; while(scanf("%d",&n) != EOF){ for(int i=0; i<=9; i++){ b[i]=pow(2,i); } for(int i=0; i<=9; i++){ if(b[i]==n){ printf("%d\n",b[i]); } for(int j=i+1; j<=9; j++){ if(b[i]+b[j]==n){ printf("%d %d\n",b[i],b[j]); } for(int k=j+1; k<=9;k++){ if(b[i]+b[j]+b[k]==n){ printf("%d %d %d\n",b[i],b[j],b[k]); } for(int l=k+1; l<=9;l++){ if(b[i]+b[j]+b[k]+b[l]==n){ printf("%d %d %d %d\n",b[i],b[j],b[k],b[l]); } for(int m=l+1; m<=9; m++){ if(b[i]+b[j]+b[k]+b[l]+b[m]==n){ printf("%d %d %d %d %d\n",b[i],b[j],b[k],b[l],b[m]); } for(int o = m+1; o<=9; o++){ if(b[i]+b[j]+b[k]+b[l]+b[m]+b[o]==n){ printf("%d %d %d %d %d %d\n",b[i],b[j],b[k],b[l],b[m],b[o]); } for(int p=o+1; p<=9; p++){ if(b[i]+b[j]+b[k]+b[l]+b[m]+b[o]+b[p]==n){ printf("%d %d %d %d %d %d %d\n",b[i],b[j],b[k],b[l],b[m],b[o],b[p]); } for(int q=p+1; q<=9; q++){ if(b[i]+b[j]+b[k]+b[l]+b[m]+b[o]+b[p]+b[q]==n){ printf("%d %d %d %d %d %d %d %d\n",b[i],b[j],b[k],b[l],b[m],b[o],b[p],b[q]); } for(int r=q+1; r<=9; r++){ if(b[i]+b[j]+b[k]+b[l]+b[m]+b[o]+b[p]+b[q]+b[r]==n){ printf("%d %d %d %d %d %d %d %d %d\n",b[i],b[j],b[k],b[l],b[m],b[o],b[p],b[q],b[r]); } for(int s=r+1; s<=9; s++){ if(b[i]+b[j]+b[k]+b[l]+b[m]+b[o]+b[p]+b[q]+b[r]+b[s]==n){ printf("%d %d %d %d %d %d %d %d %d %d\n",b[i],b[j],b[k],b[l],b[m],b[o],b[p],b[q],b[r],b[s]); } } } } } } } } } } } } return 0; } #include<stdio.h> #include<math.h> int main(){ int a,b,c; int cho=0; int hisi=0; while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){ if(pow(a,2)+pow(b,2)==pow(c,2)) cho++; if(a==b) hisi++; } printf("%d\n%d\n",cho,hisi); return 0; } #include<stdio.h> int h,i,a,b,c,x,y,z; int main(){ scanf("%d",&h); while(h--){ scanf("%d",&a); b=c=0;x=y=1; for(i=1;i<10;i++){ scanf("%d",&z); if(a>z && b>z)c=1; else if(a<z && b<z){ if(a>b)a=z; else b=z; }else{ if(a>b)b=z; else a=z; } } printf("%s\n",(c==0)?("YES"):("NO")); } return 0; } #include<stdio.h> int main(){ int d[10]; int v1,v2; int i,s=0; double t,x; while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],&d[8],&d[9],&v1,&v2)!=EOF){ s=0; for(i=0;i<10;i++){ s+=d[i]; } v2+=v1; t=(double)s/(double)v2; x=t*v1; for(i=0;i<10;i++){ if(x<=0)break; x-=d[i]; } printf("%d\n",i); } return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> typedef struct _point { double x; double y; } point_t; int whichside( point_t p1, point_t p2, point_t pa, point_t pb ) { double tc, td; tc = ( p1.x - p2.x )*( pa.y - p1.y ) - ( p1.y - p2.y )*( pa.x - p1.x ); td = ( p1.x - p2.x )*( pb.y - p1.y ) - ( p1.y - p2.y )*( pb.x - p1.x ); if ( tc*td < 0 ) { return 1; } else { return 0; } } int main() { point_t p[4], vec1, vec2; int i = 0, j, flag = 0; char str[100], * tp; double tc, td; while ( fgets( str, 100, stdin ) ) { i = 0; tp = strtok( str, "," ); while ( i < 4 ) { p[i].x = atof( tp ); tp = strtok( NULL, "," ); p[i].y = atof( tp ); tp = strtok( NULL, "," ); i++; } /* for ( i = 0 ; i < 4 ; i++ ) { printf( "%lf, %lf\n", p[i].x, p[i].y ); } */ if ( !whichside( p[0], p[2], p[1], p[3] ) ) { flag = 1; } if ( !whichside( p[1], p[3], p[0], p[2] ) ) { flag = 1; } if ( flag != 1 ) { printf( "YES\n" ); } else { printf( "NO\n" ); } } return 0; } #include <stdio.h> #include <math.h> int main(void) { int pat[4], h, i, j, v, minv; char *r, buf[9]; while (1) { for (i = 0, h = 0, minv = 255; i < 8 && (r = gets(buf)) != NULL; i++) { for (j = 0, v = 0; j < 8; j++) { v <<= 1; v += buf[j] == '1'; } if (v > 0) { pat[h++] = v; if (v < minv) minv = v; } } if (r == NULL) return 0; gets(buf); // blank line; for (i = 0; i < h; i++) { pat[i] /= minv; } if (h == 1) { puts("C"); } else if (h == 4) { puts("B"); } else if (h == 2) { if (pat[0] == 2) { puts("E"); } else if (pat[1] == 2) { puts("G"); } else { puts("A"); } } else { if (pat[0] == 1) { puts("D"); } else { puts("F"); } } } return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUF_UNIT_SIZE 10000 #define MAX_LINE_LENGTH 1000 typedef struct { int x, y; } vector_t; void complex_mul(const vector_t *v1, const vector_t *v2, vector_t *t) { t->x = v1->x * v2->x - v1->y * v2->y; t->y = v1->x * v2->y + v1->y * v2->x; } char *bufp[100], *wall[1000], path[10000]; const vector_t next_dir[] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; const char dir_char[][3] = { {' ', 'U', ' '}, {'L', ' ', 'R'}, {' ', 'D', ' '} }; int main(void) { int W, H, i; int buf_idx, buf_len, path_idx, nx, ny; char *buf; vector_t pos, dir, ndir; buf_idx = 0; buf_len = 0; buf = (char*)malloc(BUF_UNIT_SIZE * sizeof(char)); bufp[buf_idx++] = buf; for (i = 0, W = 0; gets(buf) != NULL; i++) { wall[i] = buf; if (W == 0) W = strlen(buf); buf_len += strlen(buf) + 1; if (buf_len + MAX_LINE_LENGTH > BUF_UNIT_SIZE) { buf = (char*)malloc(BUF_UNIT_SIZE * sizeof(char)); bufp[buf_idx++] = buf; buf_len = 0; } else { buf += strlen(buf) + 1; } } H = i; path_idx = 0; path[path_idx++] = 'R'; pos.x = 0; pos.y = 0; dir.x = 1; dir.y = 0; while (1) { for (i = 0; i < 3; i++) { complex_mul(&dir, &next_dir[i], &ndir); if ((pos.y&1) == 0) { ny = pos.y + ndir.y; nx = pos.x + ndir.x + (dir.x > 0)*((ny+2)&1); } else { ny = pos.y + ndir.y + dir.y; nx = pos.x + ndir.x - (ndir.x > 0); } if (nx < 0 || W+(ny&1) <= nx || ny < 0 || H <= ny) continue; if (wall[ny][nx] == '1') break; } if (i == 3) { dir.x = - dir.x; dir.y = - dir.y; } else { pos.x = nx; pos.y = ny; dir.x = ndir.x; dir.y = ndir.y; } path[path_idx++] = dir_char[1+dir.y][1+dir.x]; if ((pos.x == 0 && pos.y == 0 && dir.x == -1) || (pos.x == 0 && pos.y == 1 && dir.y == -1)) break; } path[path_idx] = '\0'; puts(path); for (i = 0; i < buf_idx; i++) { free(bufp[i]); } return 0; } #include <stdio.h> int cmp_int(const void *a, const void *b) { return *(int*)a - *(int*)b; } int main(void) { int c[5]; int cmb[5], m, incr, i; char *hand; while (scanf("%d", &c[0]) == 1) { for (i = 1; i < 5; i++) { scanf(",%d", &c[i]); cmb[i] = 0; } qsort(c, 5, sizeof(int), cmp_int); for (i = 1, m = 1, incr = 0; i < 5; i++) { m = c[i-1] == c[i]? m + 1: 1; cmb[m]++; incr += (c[i] - c[i-1]) == 1; } if (incr == 4 || (c[0] == 1 && c[1] == 10 && incr == 3)) { hand = "straight"; } else if (cmb[4]) { hand = "four card"; } else if (cmb[3] && cmb[2] == 2) { hand = "full house"; } else if (cmb[3]) { hand = "three card"; } else if (cmb[2] == 2) { hand = "two pair"; } else if (cmb[2]) { hand = "one pair"; } else { hand = "null"; } puts(hand); } return 0; } #include <stdio.h> int main(void) { char str[128]; int ans; int i; while(scanf("%s", str) != EOF){ ans = 0; for(i = 0; str[i] != '\0'; i++){ switch(str[i]){ case 'I': if(str[i+1] == 'V' || str[i+1] == 'X') ans -= 1; else ans += 1; break; case 'V': ans += 5; break; case 'X': if(str[i+1] == 'L' || str[i+1] == 'C') ans -= 10; else ans += 10; break; case 'L': ans += 50; break; case 'C': if(str[i+1] == 'D' || str[i+1] == 'M') ans -= 100; else ans += 100; break; case 'D': ans += 500; break; case 'M': ans += 1000; break; } } printf("%d\n", ans); } return 0; } #include <stdio.h> #include <string.h> void cipher(void); int main(void){ int i,j,k,n,len,a,b; char data1[1024],data2[1024]; scanf("%d ",&n); for(i=0;i<n;i++){ gets(data1); for(j=0;j<1024;j++){ data2[j]='\0'; } len=strlen(data1); for(a=0;a<26;a++){ for(b=0;b<26;b++){ if(strstr(data2,"this")!=NULL) goto end; if(strstr(data2,"that")!=NULL) goto end; for(k=0;k<len;k++){ if(data1[k]>='a' && data1[k]<='z') data2[k]=(a*(data1[k]-'a')+b)%26+'a'; if(data1[k]==' ') data2[k]=' '; if(data1[k]=='.') data2[k]='.'; } } } end: puts(data2); } return 0; } #include<stdio.h> #include<string.h> int S[30],ST[9],N[7]={0,0,0,0,43,45,42},i,p,F[4]={0}; int calc() { int i=p=0; for(i=0;i<7;i++) { if(S[i]>9) { if(p<2)return 0; else if(S[i]==43)ST[p-2]=ST[p-2]+ST[p-1]; else if(S[i]==45)ST[p-2]=ST[p-2]-ST[p-1]; else if(S[i]==42)ST[p-2]=ST[p-2]*ST[p-1]; p-=1; } else ST[p++]=S[i]; } return ST[0]; } int dfs(int d,int f[4]) { int i; if(d==7) { if(calc()==10) { if(S[4]>9&&S[5]>9&&S[6]>9)return 0; else if(S[0]<10&&S[1]<10&&S[2]<10)return 0; else if(S[4]>9) printf("(((%d %c %d) %c %d) %c %d)\n",S[0],S[2],S[1],S[4],S[3],S[6],S[5]); else printf("((%d %c %d) %c (%d %c %d))\n",S[0],S[2],S[1],S[6],S[3],S[5],S[4]); return 1; } return 0; } for(i=0;i<7;i++) { if((i<4&&!f[i])||i>3) { f[i]=1; S[d]=N[i]; if(dfs(d+1,f))return 1; f[i]=0; } } return 0; } int main() { for(;~scanf("%d%d%d%d",&N[0],&N[1],&N[2],&N[3]),N[0];) { memset(F,0,16); if(dfs(0,F)==0) puts("0"); } return 0; } #include <stdio.h> typedef struct{ int sum_v; int sum_w; }tre; int max_w, n, v[1000], w[1000]; int sum_w; tre memo[1001][1001]; tre dp(int i, int j); int main(void){ int num = 1; int i, j; tre treasure; while(1){ scanf("%d", &max_w); if(max_w == 0) break; scanf("%d", &n); for(i=0; i<n; i++){ scanf("%d,%d", &v[i], &w[i]); } for(i=0; i<1001; i++){ for(j=0; j<1001; j++){ memo[i][j].sum_v = -1; memo[i][j].sum_w = -1; } } treasure = dp(0, max_w); printf("Case %d:\n", num); printf("%d\n", treasure.sum_v); printf("%d\n", treasure.sum_w); num++; } return 0; } tre dp(int i, int j){ if((memo[i][j]).sum_v >= 0){ return memo[i][j]; } tre t; tre temp_1, temp_2; if(i == n){ t.sum_v = 0; t.sum_w = 0; }else if(j < w[i]){ temp_1 = dp(i+1, j); t.sum_v = temp_1.sum_v; t.sum_w = temp_1.sum_w; }else{ temp_1 = dp(i+1, j); temp_2 = dp(i+1, j-w[i]); if(temp_2.sum_v + v[i] > temp_1.sum_v){ t.sum_v = temp_2.sum_v + v[i]; t.sum_w = temp_2.sum_w + w[i]; }else if(temp_2.sum_v + v[i] < temp_1.sum_v){ t.sum_v = temp_1.sum_v; t.sum_w = temp_1.sum_w; }else{ if(temp_2.sum_w + w[i] > temp_1.sum_w){ t.sum_v = temp_1.sum_v; t.sum_w = temp_1.sum_w; }else{ t.sum_v = temp_2.sum_v + v[i]; t.sum_w = temp_2.sum_w + w[i]; } } } return memo[i][j] = t; } #include<stdio.h> #include<stdlib.h> #include<string.h> int t=0; int mentsu(int pi[12]){ int i=1,m=1,r=0; while(pi[m]==0&&m<10)m++; if(pi[m]!=0&&pi[m+1]!=0&&pi[m+2]!=0){ pi[m]--; pi[m+1]--; pi[m+2]--; r=mentsu(pi); pi[m]++; pi[m+1]++; pi[m+2]++; } if(pi[m]>2&&r==0){ pi[m]-=3; r=mentsu(pi); pi[m]+=3; } if(t==0&&pi[m]>1&&r==0){ if(pi[m]>1){ pi[m]-=2; t=1; r=mentsu(pi); t=0; pi[m]+=2; } } if(m==10||r==1)return 1; else return 0; } int main(){ char s[14]={'\0'}; int n[14],i,j,a; while(fgets(s,14,stdin)!=NULL){ if(strlen(s)==13){ a=0; for(i=1;i<10;i++){ int pi[12]={0}; for(j=0;j<13;j++){ pi[s[j]-'0']++; } pi[i]++; if(pi[i]<5){ if(mentsu(pi)){ if(a==1)printf(" "); printf("%d",i); a=1; } } } if(a==0)printf("0"); printf("\n"); } } return 0; } #include <stdio.h> #define MAX 60000 void maketable( int sosu[MAX] ) { sosu[0] = -1, sosu[1] = -1; int i, j; for ( i = 2 ; i < MAX ; i++ ) { if ( sosu[i] == 0 ) { sosu[i] = 1; for ( j = 2*i ; j < MAX ; j += i ) { sosu[j] = -1; } } } return; } int main() { int sosu[MAX], i, j; int n = 0, minum, maxnum; maketable( sosu ); while ( scanf( "%d", &n ) != EOF ) { for ( i = n-1 ; i > 0 ; i-- ) { if ( sosu[i] == 1 ) { minum = i; break; } } for ( i = n+1 ; i < MAX ; i++ ) { if ( sosu[i] == 1 ) { maxnum = i; break; } } printf( "%d %d\n", minum, maxnum ); } return 0; } #include <stdio.h> int main(void){ int a,b; int sum=0,sum2=0; int cnt=0; while(scanf("%d,%d",&a,&b)!=EOF){ sum+=a*b; sum2+=b; cnt++; } printf("%d\n%d\n",sum,(sum2+(cnt/2))/cnt); return 0; } #include<stdio.h> int main(void){ double x[50],min,max; scanf("%lf",&x[0]); min=x[0]; max=x[0]; int i=1; while(scanf("%lf",&x[i])!=EOF){ if(min>x[i]){ double a; a=min; min=x[i]; x[i]=a; } if(max<x[i]){ double a; a=min; max=x[i]; x[i]=a; } i++; } printf("%lf\n",max-min); return 0; } p=65;main(s){for(;~scanf("%s",&s);p=s>64?s:p)s=s&255^s>>16^p;p=!puts(&p);} #include <stdio.h> int main(void){ double n; while(scanf("%lf\n",&n)!=EOF){ if(n<=48.00){ printf("light fly\n"); } if(48.00<n&&n<=51.00){ printf("fly\n"); } if(51.00<n&&n<=54.00){ printf("bantam\n"); } if(54.00<n&&n<=57.00){ printf("feather\n"); } if(57.00<n&&n<=60.00){ printf("light\n"); } if(60.00<n&&n<=64.00){ printf("light welter\n"); } if(64.00<n&&n<=69.00){ printf("welter\n"); } if(69.00<n&&n<=75.00){ printf("light middle\n"); } if(75.00<n&&n<=81.00){ printf("middle\n"); } if(81.00<n&&n<=91.00){ printf("light heavy\n"); } if(n>91.00){ printf("heavy\n"); } } } #include <stdio.h> #include <string.h> int main(void) { int i=0, count[4]={0}; char c[3]; while( scanf("%d, %s", &i, c) != EOF) { if(strcmp(c,"A")==0) count[0]++; else if(strcmp(c,"B")==0) count[1]++; else if(strcmp(c,"O")==0) count[3]++; else count[2]++; } for(i=0; i<4; i++) printf("%d\n", count[i]); return 0; } #include <stdio.h> #include <string.h> int main (void) { int i; char buf[1001], *ch; const char *words[] = { "apple", "peach" }; while (gets(buf) != NULL) { ch = buf; while (*ch != '\0') { for (i = 0; i < 2; i++) { if (strncmp(ch, words[i], 5) == 0) { printf("%s", words[i^1]); ch += 5; break; } } if (i == 2) { putc(*ch, stdout); ch++; } } puts(""); } return 0; } #include<stdio.h> int main(){ int max,min,n,k,d,t; scanf("%d",&n); for(k=0;k<n;k++){ scanf("%d",&d); int i,j,s[8]={0}; for(i=0;d!=0;i++){ s[i]=d%10; d/=10; } for(i=0;i<8;i++){ for(j=1;j+i<8;j++){ if(s[j-1]<s[j]){ t=s[j-1]; s[j-1]=s[j]; s[j]=t; } } } max=0; for(i=0;i<8;i++){ max*=10; max+=s[i]; } for(i=0;i*2<8;i++){ t=s[i]; s[i]=s[7-i]; s[7-i]=t; } min=0; for(i=0;i<8;i++){ min*=10; min+=s[i]; } printf("%d\n",max-min); } return 0; } #include <stdio.h> int main(void) { int n,i; while(1) { scanf("%d", &n); if(n==0) break; int c2=0, c5=0; for(i=n; i>0; i--) { int k=i; while(k%2==0) { k = k/2; c2++; } while(k%5==0) { k=k/5; c5++; } } printf("%d\n", (c2>c5)?c5:c2); } return 0; } #include<stdio.h> int main(){ int p[100000]={2}; int i,j,n,c=1,s=0; for(i=3;i<1000000;i+=2){ s=0; for(j=0;p[j]*p[j]<=i;j++){ if(i%p[j]==0){ s=1; break; } } if(s==0){ p[c]=i; c++; } } while(1){ scanf("%d",&n); if(n==0)break; s=0; for(i=0;i<n;i++){ s+=p[i]; } printf("%d\n",s); } return 0; } #include <stdio.h> int main() { int a,b,n; int sum, i; while( scanf( "%d%d%d", &a, &b, &n ) == 3 ){ sum = 0; a = a % b; for ( i = 0 ; a > 0 && i < n ; i++ ) { a = a * 10; sum = a / b + sum; a = a % b; } printf( "%d\n", sum ); } return 0; } #include <stdio.h> int main() { double a, b, sum; int i, n; while ( scanf( "%lf", &a ) == 1 ) { sum = 0; for ( i = 0 ; i < 10 ; i++ ) { sum = sum + a; if ( i % 2 == 0 ) { a = a * 2; } else { a = a / 3; } } printf( "%.8lf\n", sum ); } return 0; } #include <stdio.h> #define MAX 50001 int makePrimeTable( int * table ) { int i, j; for ( i = 0 ; i < MAX ; i++ ) { table[i] = 0; } for ( i = 2 ; i < MAX ; i++ ) { if ( table[i] == 0 ) { for ( j = 2 ; i * j < MAX ; j++ ) { table[i*j] = 1; } } } return 0; } int main() { int n, i, j, cnt; int ptable[MAX]; makePrimeTable( ptable ); while ( scanf( "%d", &n ) == 1 ) { cnt = 0; if ( n == 0 ) { break; } else { for ( i = 2 ; i <= n / 2 ; i++ ) { if ( ptable[i] == 0 && ptable[n-i] == 0 ) { cnt++; } } printf( "%d\n", cnt ); } } return 0; } #include <stdio.h> int main(void){ int n; while(scanf("%d",&n)!=EOF){ printf("%d\n",n*(n+1)/2+1); } } #include <stdio.h> int main() { float x1, y1, x2, y2, x3, y3, x4, y4; float vecx1, vecy1, vecx2, vecy2; while ( scanf( "%f %f %f %f %f %f %f %f", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4 ) == 8 ) { vecx1 = x1 - x2; vecy1 = y1 - y2; vecx2 = x3 - x4; vecy2 = y3 - y4; if ( vecx1 * vecx2 + vecy1 * vecy2 == 0 ) { printf( "YES\n" ); } else { printf( "NO\n" ); } } return 0; } #include <stdio.h> int main() { double xa1, ya1, xa2, ya2; double xb1, yb1, xb2, yb2; int tmp; while ( scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2 ) == 8 ) { if ( xa2 < xb1 || xb2 < xa1 || ya2 < yb1 || yb2 < ya1 ) { printf( "NO\n" ); } else { printf( "YES\n" ); } } return 0; } #include <stdio.h> int main() { int c1, c2, c3, i, cnt = 0; int card[11]; for ( int i = 1 ; i < 11 ; i++ ) { card[i] = 1; } while ( scanf( "%d %d %d", &c1, &c2, &c3 ) == 3 ) { cnt = 0; for ( i = 1 ; i < 11 ; i++ ) { if ( c1 != i && c2 != i && c3 != i ) { if ( c1 + c2 + i <= 20 ) { cnt++; } } } if ( cnt >= 4 ) { printf( "YES\n" ); } else { printf( "NO\n" ); } } return 0; } #include <stdio.h> #include <stdlib.h> typedef struct _team { int p; int s; int no; } team_t; int main() { team_t t[100]; int i = 0, j = 0; int number[31] = { 0 }; char *str; while ( scanf( "%d,%d", &t[i].p, &t[i].s ) == 2 ){ if ( t[i].p == 0 && t[i].s == 0 ) { break; } number[t[i].s]++; i++; } j = 30; i = 1; while ( j >= 0 ) { if ( number[j] > 0 ) { number[j] = i; i++; } j--; } while ( scanf( "%d", &i ) == 1 ) { printf( "%d\n", number[t[i-1].s] ); } return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char str[10]; int num[10][10], i, j; while ( scanf( "%s", str ) == 1 ) { for ( i = 0 ; i < 10 ; i++ ) { num[0][i] = str[i] - 48; } for ( j = 1 ; j < 10 ; j++ ) { for ( i = 0 ; i < 10 - j ; i++ ) { num[j][i] = ( num[j-1][i] + num[j-1][i+1] ) % 10; } } printf( "%d\n", num[j-1][0] ); } return 0; } #include <stdio.h> #include <string.h> int ispalin(char * s,int len) { if(len < 2) return(-1); else if(len ==2) return(s[0]==s[1]?(-1):0); else if(s[0]==s[len-1] ) return(ispalin(s+1,len-2)); else return(0); } main() { char s[101]; int cnt=0; while(EOF != scanf("%s",s)) { if(ispalin(s,strlen(s))) { cnt++; /*printf("palin\n");*/ } } printf("%d\n",cnt); return(0); } #include <stdio.h> #include <ctype.h> int main() { char str[81], tmp[6]; int num = 0, i, sum = 0; while ( scanf( "%s", str ) == 1 ) { i = 0; while ( str[i] ) { if ( isdigit( str[i] ) ) { num = 0; while ( isdigit( str[i] ) ) { num = 10 * num + ( str[i] - '0' ); i++; } sum = sum + num; } else { i++; } } } printf( "%d\n", sum ); return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct _data { int pre; int this; int trading_time; } data_t; int main() { data_t d[1001]; int i = 0, c, di; char * p, tmp1[5], tmp2[3], tmp[8]; while ( i < 1001 ) { d[i].pre = 0; d[i].this = 0; d[i].trading_time = 0; i++; } while ( fgets( tmp, 8, stdin ) != NULL ) { if ( tmp[0] == '\n' ) { break; } i = 0; while ( tmp[i] != ',' ) { tmp1[i] = tmp[i]; i++; } tmp1[i] = '\0'; c = atoi( tmp1 ); di = atoi( &tmp[i+1] ); d[c].pre = di; d[c].trading_time++; } while ( scanf( "%d,%d", &c, &di ) == 2 ) { d[c].this = di; d[c].trading_time++; } for ( i = 0 ; i < 1001 ; i++ ) { if ( d[i].this > 0 && d[i].pre > 0 ) { printf( "%d %d\n", i, d[i].trading_time ); } } return 0; } #include <stdio.h> int main() { char str[10]; while ( scanf( "%s", str ) == 1 ) { if ( str[0] == str[1] && str[0] == str[2] && str[0] != 's' ) { printf( "%c\n", str[0] ); } else if ( str[3] == str[4] && str[3] == str[5] && str[3] != 's' ) { printf( "%c\n", str[3] ); } else if ( str[6] == str[7] && str[6] == str[8] && str[6] != 's' ) { printf( "%c\n", str[6] ); } else if ( str[0] == str[3] && str[0] == str[6] && str[0] != 's' ) { printf( "%c\n", str[0] ); } else if ( str[1] == str[4] && str[1] == str[7] && str[1] != 's' ) { printf( "%c\n", str[1] ); } else if ( str[2] == str[5] && str[2] == str[8] && str[2] != 's' ) { printf( "%c\n", str[2] ); } else if ( str[0] == str[4] && str[0] == str[8] && str[0] != 's' ) { printf( "%c\n", str[0] ); } else if ( str[2] == str[4] && str[2] == str[6] && str[2] != 's' ) { printf( "%c\n", str[2] ); } else { printf( "d\n" ); } } return 0; } #include <stdio.h> void delcntland( char map[13][13], int y, int x ) { map[y][x] = '0'; if ( x+1 < 12 && map[y][x+1] == '1' ) { delcntland( map, y, x+1 ); } if ( y+1 < 12 && map[y+1][x] == '1' ) { delcntland( map, y+1, x ); } if ( x-1 >= 0 && map[y][x-1] == '1' ) { delcntland( map, y, x-1 ); } if ( y-1 >= 0 && map[y-1][x] == '1' ) { delcntland( map, y-1, x ); } } int main() { char map[13][13]; int i = 0, j = 0, island = 0; while ( 1 ) { for ( i = 0 ; i < 12 ; i++ ) { if ( scanf( "%s", map[i] ) == EOF ) { return 0; } } island = 0; for ( i = 0 ; i < 12 ; i++ ) { for ( j = 0 ; j < 12 ;j++ ) { if ( map[i][j] == '1' ) { delcntland( map, i, j ); island++; } } } printf( "%d\n", island ); } return 0; } #include<stdio.h> #include<math.h> int main(){ int n,i,mi,mj,c; double max,m,ax,ay,by,bx,x[100],y[100]; while(scanf("%d",&n),n){ int f[100]={0}; ay=1; ax=max=0; for(i=0;i<n;i++){ scanf("%lf,%lf",&x[i],&y[i]); if(max<x[i])max=x[mi=i]; } for(c=0;f[mi]==0;c++){//printf("%d\n",mi); f[mi]=1; for(i=max=0;i<n;i++){ if(mi==i)continue; bx=x[i]-x[mi]; by=y[i]-y[mi]; m=(ax*bx+ay*by)/(hypot(ay,ax)*hypot(bx,by)); if(ax*by<ay*bx)m=1-m; else m+=3; if(max<m){ max=m; mj=i; } } ax=x[mj]-x[mi]; ay=y[mj]-y[mi]; mi=mj; } printf("%d\n",n-c); } return 0; } #include <stdio.h> int main(void) { char bar[31][11] = {}; int n, m, lucky, d, i, r, c; int route[31], lroute[31]; while (scanf("%d", &n) != EOF && n) { scanf("%d", &m); scanf("%d", &lucky); scanf("%d", &d); route[0] = m; for (i = 1; i <= d; i++) { scanf("%s", &(bar[i][1])); bar[i][0] = bar[i][n] = '0'; if (bar[i][route[i-1]-1] == '1') { route[i] = route[i-1] - 1; } else if (bar[i][route[i-1]] == '1') { route[i] = route[i-1] + 1; } else { route[i] = route[i-1]; } } if (route[d] == lucky) { puts("0"); continue; } lroute[d] = lucky; for (i = d - 1; i >= 1; i--) { if (bar[i+1][lroute[i+1]-1] == '1') { lroute[i] = lroute[i+1] - 1; } else if (bar[i+1][lroute[i+1]] == '1') { lroute[i] = lroute[i+1] + 1; } else { lroute[i] = lroute[i+1]; } } for (i = 1, r = 0, c = 0; i <= d; i++) { if (route[i] + 1 == lroute[i] && bar[i][route[i]-1]=='0' && bar[i][route[i]]=='0' && bar[i][route[i]+1]=='0') { r = i; c = route[i]; break; } else if (route[i] - 1 == lroute[i] && bar[i][route[i]-2]=='0' && bar[i][route[i]-1]=='0' && bar[i][route[i]]=='0') { r = i; c = route[i] - 1; break; } } if (r != 0) { printf("%d %d\n", r, c); } else { puts("1"); } } return 0; } #include<stdio.h> int m,f[10],d[]={0,9,26,50,80,115,154,196,240,285,330}; int g(int a,int b){//printf("%d %d\n",a,b); int i,s=0; if(m>b+d[a]||b>m)return 0; if(b>m)return 0; if(a==0)return b-m?0:1; for(i=0;i<10;i++){ if(f[i])continue; f[i]=1; s+=g(a-1,b+i*a); f[i]=0; } return s; } int main(){ int n,i,j,s; while(~scanf("%d %d",&n,&m))printf("%d\n",g(n,0)); return 0; } #include <stdio.h> const int dir[][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}}; void explode(char field[10][10], int px, int py) { int i, j, x, y; field[py][px] = '0'; for (i = 0; i < 4; i++) { for (j = 1; j <= 3; j++) { x = px + j * dir[i][0]; y = py + j * dir[i][1]; if (x < 1 || 8 < x || y < 1 || 8 < y) break; if (field[y][x] == '1') explode(field, x, y); } } } int main(void) { char field[10][10]; int N, n, i, sx, sy; gets(field[0]); sscanf(field[0], "%d", &N); for (n = 1; n <= N; n++) { for (i = 0; i <= 8; i++) { gets(&(field[i][1])); } gets(field[0]); sscanf(field[0], "%d", &sx); gets(field[0]); sscanf(field[0], "%d", &sy); explode(field, sx, sy); printf("Data %d:\n", n); for (i = 1; i <= 8; i++) { puts(&(field[i][1])); } } return 0; } #include<stdio.h> int n,m,a[10000],b[10000],c[10000],d[10010],i,j,r[10010],t,s; int main(){ while(scanf("%d",&n),n){ scanf("%d",&m); for(i=0;i<m;i++){ r[i]=i; scanf("%d,%d,%d",&a[i],&b[i],&c[i]); a[i]++; b[i]++; for(j=i;j;j--){ if(c[r[j-1]]>c[r[j]]){ t=r[j-1]; r[j-1]=r[j]; r[j]=t; } } } int p[10010]={0}; for(i=s=0;i<m;i++){ for(;p[a[r[i]]];a[r[i]]=p[a[r[i]]]); for(;p[b[r[i]]];b[r[i]]=p[b[r[i]]]); if(b[r[i]]-a[r[i]]){ if(d[a[r[i]]]< d[b[r[i]]])p[a[r[i]]]=b[r[i]]; if(d[b[r[i]]]<=d[a[r[i]]])p[b[r[i]]]=a[r[i]]; if(d[a[r[i]]]==d[b[r[i]]])d[b[r[i]]]++; s+=c[r[i]]-100;//printf("%d", } } printf("%d\n",s/100); } return 0; } #include <stdio.h> #include <math.h> int main(void){ double x,h,high,s; while(scanf("%lf %lf",&x,&h)!=EOF){ if(x==0&&h==0){ break; } high=sqrt(h*h+(x/2)*(x/2)); s=x*x+x*high/2*4; printf("%f\n",s); } } #include <stdio.h> int main(void) { int h, m, s, cur_sec, remaining; while (scanf("%d%d%d", &h, &m, &s) == 3 && h != -1 && m != -1 && s != -1) { cur_sec = h * 3600 + m * 60 + s; remaining = 2 * 3600 - cur_sec; printf("%02d:%02d:%02d\n", remaining / 3600, (remaining % 3600) / 60, remaining % 60); remaining *= 3; printf("%02d:%02d:%02d\n", remaining / 3600, (remaining % 3600) / 60, remaining % 60); } return 0; } #include<stdio.h> int main(void){ int s; double w,h,b; while(scanf("%d,%lf,%lf",&s,&w,&h) != EOF){ b=w/h/h; if(b>=25){ printf("%d\n",s); } } return 0; } #include <stdio.h> #include <math.h> int main(void) { int n, i; double t, l; while (scanf("%d", &n) != EOF && n != -1) { for (i = 2, t = 0; i <= n; i++) { t += atan2(1, sqrt(i - 1)); } l = sqrt(n); printf("%.2lf\n%.2lf\n", l * cos(t), l * sin(t)); } return 0; } #include <stdio.h> #include <string.h> #define MAX 100 int main(void) { char str[MAX]; int i, j; int length; while(scanf("%s", str) != EOF) { length = strlen(str); for(i=0; i<length; ++i) { if(str[i] == '@') { for(++i, j=0; j<str[i]-'0'; ++j) { printf("%c", str[i+1]); } i += 1; continue; } else { printf("%c", str[i]); } } printf("\n"); } return 0; } #include <stdio.h> #define MAX 15 int main(void){ int n, i, j, nx, ny, sum; int magic[MAX][MAX]; while(1){ for(i = 0; i < MAX; i++){ for(j = 0; j < MAX; j++){ magic[i][j] = 0; } } scanf("%d", &n); if(n == 0){ break; } magic[n / 2 + 1][n / 2] = 1; nx = n / 2 + 1; ny = n / 2; for(i = 2; i <= n * n; i++){ nx++; ny++; while(1){ nx = (nx + n) % n; ny = (ny + n) % n; if(magic[nx][ny] == 0){ magic[nx][ny] = i; break; } nx++; ny--; } } for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ printf("%4d", magic[i][j]); } printf("\n"); } } return 0; } #include<stdio.h> double x[22]; double y[22]; int main(){ double a,b; int now=1; while(~scanf("%lf,%lf",&a,&b)){ x[now]=a; y[now++]=b; } x[0]=x[now-1]; x[now]=x[1]; double S=0; for(int i=1;i<now;i++){ S+=(x[i+1]-x[i-1])*y[i]; } if(S<0)S=-S; printf("%.8lf",S/2.0); } #include <stdio.h> #include <math.h> #define EPS 1e-5 int main (void) { int q; double px, x; while (scanf("%d", &q) != EOF && q != -1) { px = (double)q / 2; do { x = px - (px*px*px - q) / (3*px*px); px = x; } while (fabs(x*x*x - q) >= EPS * q); printf("%.6lf\n", x); } return 0; } #include <stdio.h> int main(void) { double x1, y1, x2, y2, xq, yq, m; while ((scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq)) != EOF) { x2 -= x1; y2 -= y1; xq -= x1; yq -= y1; m = (x2 * xq + y2 * yq) / (x2 * x2 + y2 * y2); printf("%.6lf %.6lf\n", x1 + 2*m*x2 - xq, y1 + 2*m*y2 - yq); } return 0; } #include <stdio.h> #include <limits.h> int main(void) { const int merry[] = {1, 2, 1, 2, 1, 4, 1, 4}; int p[8], i, j, k, d, dmin, check, min_check; while (scanf("%d", &p[0]) == 1) { for (i = 1; i < 8; i++) { scanf("%d", &p[i]); } for (i = 0, dmin = INT_MAX, k = 0, min_check = 9999; i < 8; i++) { for (j = 0, d = 0; j < 8; j++) { d += p[j] > merry[(i+j)%8]? p[j]-merry[(i+j)%8]: 0; } check = merry[i]*1000 + merry[(i+1)%8]*100 + merry[(i+2)%8]*10 + merry[(i+3)%8]; if (d < dmin || (d == dmin && check < min_check)) { dmin = d; min_check = check; k = i; } } printf("%d", merry[k]); for (i = 1; i < 8; i++) { printf(" %d", merry[(k+i)%8]); } puts(""); } return 0; } #include <stdio.h> #include <stdbool.h> typedef enum { MEIJI, TAISHO, SHOWA, HEISEI, PREMEIJI }Era_name; Era_name judge_era_name(int year, int month, int day); int main() { int year, month, day; Era_name era_name; while (true) { if (scanf("%d %d %d", &year, &month, &day) == EOF) { break; } else { era_name = judge_era_name(year, month, day); switch (era_name) { case MEIJI: printf("meiji %d %d %d\n", year - 1867, month, day); break; case TAISHO: printf("taisho %d %d %d\n", year - 1911, month, day); break; case SHOWA: printf("showa %d %d %d\n", year - 1925, month, day); break; case HEISEI: printf("heisei %d %d %d\n", year - 1988, month, day); break; case PREMEIJI: printf("pre-meiji\n"); break; default: break; } } } return 0; } Era_name judge_era_name(int year, int month, int day) { if (year < 1868) { return PREMEIJI; } if (year == 1868) { if (month < 9) { return PREMEIJI; } else if (month == 9) { if (day < 8) { return PREMEIJI; } else { return MEIJI; } } else { return MEIJI; } } if (year > 1868 && year < 1912) { return MEIJI; } if (year == 1912) { if (month < 7) { return MEIJI; } else if (month == 7) { if (day < 30) { return MEIJI; } else { return TAISHO; } } else { return TAISHO; } } if (year > 1912 && year < 1926) { return TAISHO; } if (year == 1926) { if (month < 12) { return TAISHO; } else if (month == 12) { if (day < 25) { return TAISHO; } else { return SHOWA; } } else { return SHOWA; } } if (year > 1926 && year < 1989) { return SHOWA; } if (year == 1989) { if (month < 1) { return SHOWA; } else if (month == 1) { if (day < 8) { return SHOWA; } else { return HEISEI; } } else { return HEISEI; } } if (year > 1989) { return HEISEI; } } #include<stdio.h> int main(){ char s[1206],w[1204]; int c=0,i,a=1; fgets(s,1205,stdin); for(i=0;s[i]!=0;i++){ if((s[i]==' ')||(s[i]=='.')||(s[i]==',')){ if(2<c&&c<7){ if(a==0)printf(" "); printf("%s",w); a=0; } c=0; } else{ w[c]=s[i]; c++; w[c]='\0'; } } printf("\n"); return 0; } #include<stdio.h> int a[1010],m,n,i,b,c; int main(){ scanf("%d%d",&n,&m); while(n!=0 && m!=0){ for(i=1;i<=n;i++)a[i]=1; b=i=n; while(b>1){ c=0; while(c<m){ i++;if(i>n)i=1; c+=a[i]; } a[i]=0;b--; } for(i=1;i<=n;i++)if(a[i]==1)printf("%d\n",i); scanf("%d%d",&n,&m); } return 0; } /* Eulerian path */ #include <stdio.h> #include <string.h> int main(void) { int s, t, result, last_vertex, i, v[101]; int odd; while (1) { memset(v, 0, sizeof(v)); last_vertex = 2; odd = 0; while ((result = scanf("%d%d", &s, &t)) != EOF) { if (!s && !t) break; v[s]++; v[t]++; if (last_vertex < s) last_vertex = s; if (last_vertex < t) last_vertex = t; } if (result == EOF) return 0; for (i = 3; i <= last_vertex; i++) { if (v[i]&1) { odd++; } } if (odd == 0 && (v[1]&1) && (v[2]&1)) { puts("OK"); } else { puts("NG"); } } return 0; } #include <stdio.h> int main(void) { char buf[100], *csr; int si; double s[40], v; while (gets(buf) != NULL) { csr = buf; si = 0; while (*csr != '\0') { while (*csr == ' ') csr++; if (sscanf(csr, "%lf", &v) == 1) { while (*csr == '-' || ('0' <= *csr && *csr <= '9')) csr++; s[si++] = v; } else { si--; switch (*csr) { case '+': s[si-1] = s[si-1] + s[si]; break; case '-': s[si-1] = s[si-1] - s[si]; break; case '*': s[si-1] = s[si-1] * s[si]; break; case '/': s[si-1] = s[si-1] / s[si]; break; default: break; } csr++; } } printf("%.6lf\n", s[0]); } return 0; } #include <stdio.h> #include <string.h> // 32 - const char *c2b[] = { "101", "", "", "", "", "", "", "000000", "", "", "", "", "000011", "10010001", "010001", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "000001", "", "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000" }; const char b2c[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '.', ',', '-', '\'', '?' }; void print_char(const char *code) { int i, v = 0; for (i = 0; i < 5; i++) { v <<= 1; v += code[i] == '1'; } putc(b2c[v], stdout); } int main(void) { int c, codelen, bpos; const char *bcode, *cur; char codebuf[6]; codelen = 0; bpos = 0; cur = c2b[1]; while (1) { c = getc(stdin); if (c == '\n' || c == EOF) { if (codelen > 0) { for (; bpos < 5; bpos++) { if (*cur == '\0') { codebuf[bpos] = '0'; } else { codebuf[bpos]= *cur++; } } print_char(codebuf); codelen = 0; bpos = 0; } if (c == EOF) return 0; putc(c, stdout); continue; } bcode = c2b[c - 32]; codelen += strlen(bcode); for (; bpos < 5; bpos++) { if (*cur == '\0') { if (bcode != NULL) { cur = bcode; bcode = NULL; } else { break; } } codebuf[bpos] = *cur++; } while (codelen >= 5) { for (; bpos < 5; bpos++, cur++) { codebuf[bpos] = *cur; } print_char(codebuf); bpos = 0; codelen -= 5; } } return 0; } #include<stdio.h> #include<stdlib.h> #include<string.h> int D[105][55],i,j,t,x,dp[105][55]; char d[305],*p; int max(int a,int b){return a>b?a:b;} int main() { memset(D,-1,sizeof(D)); memset(dp,-1,sizeof(dp)); for(t=0;gets(d);t++) { d[strlen(d)]=','; j=0; p=strtok(d,","); do{D[t][j++]=atoi(p);}while(p=strtok(NULL,",")); memset(d,0,sizeof(d)); } dp[0][0]=D[0][0]; for(i=0;i<t;i++) for(j=0;D[i][j]!=-1;j++) { if(D[i+1][j]!=-1)dp[i+1][j]=max(dp[i+1][j],dp[i][j]+D[i+1][j]); if(i<(t/2)&&D[i+1][j+1]!=-1)dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+D[i+1][j+1]); if(i>=(t/2)&&j>0)dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+D[i+1][j-1]); } printf("%d\n",dp[t-1][0]); return 0; } #include<stdio.h> #include<string.h> #include<math.h> int N,i,j,k,c,t,R; double P[100][2],y,x,p[2]; int dis(double a[2],double b[2]) { double x=a[0]-b[0],y=a[1]-b[1]; return (x*x+y*y<=1.001)?1:0; } int main() { for(;scanf("%d",&N),N;) { R=1; for(i=0;i<N;i++) scanf("%lf,%lf",&P[i][0],&P[i][1]); for(p[0]=0;p[0]<10.1;p[0]+=0.01) for(p[1]=0;p[1]<10.1;p[1]+=0.01) { for(i=t=0;i<N;i++) if(dis(p,P[i])) t++; R=t>R?t:R; } printf("%d\n",R); } return 0; } #include<stdio.h> int a[1000][1000]; int way,n; //int call=0; int square(int i, int j, int k){ int x,y; //call++; if(i+k>n||j+k>n) return 0; for(x=i;x<i+k;x++){ for(y=j;y<j+k;y++){ if(!a[x][y]) return 0; } } return k; } int main(){ int i,j,k,c,max; for(;;){ scanf("%d",&n); if(n==0) break; max=0; for(i=0;i<n;i++){ for(j=0;j<n;j++){ for(;;){ c=getchar(); if(c=='.'){ a[i][j]=1; max=1; break; } else if(c=='*'){ a[i][j]=0; break; } } } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ for(k=1;k<=n;k++){ int tmp=square(i,j,k); if(max<tmp) max=tmp; else if(tmp==0) break; } } } printf("%d\n",max); } //printf("Call:%d\n",call); return 0; } #include <stdio.h> void leap_year(int x, int y); int main(void) { while (1) { static int first_or_not = 0;//二回目以降空行を入れるため. int op, ed; scanf("%d %d", &op, &ed); if (op == 0 && ed == 0) { break; } else { if (first_or_not != 0) { printf("\n"); } leap_year(op, ed); first_or_not = 1; } } return 0; } void leap_year(int op, int ed) { int i; int count = 0; for (i = op; i <= ed; i++) { if ((i % 4 == 0 && i % 100 != 0) || (i % 400 == 0)) { printf("%d\n", i); count++; } } if (count == 0) { printf("NA\n"); } } #include <stdio.h> struct _log { int i; long t; }; typedef struct _log log; int main() { while(1) { int n, j, k; int count = 0; long t; scanf("%d",&n); if (n == 0) break; for (j = 0; j < n; j++) { log l[4000]; int i, p, q; int idx = -1; scanf("%d %d %d",&i, &p, &q); t = (long)p * (long)q; for (k = 0; k < j; k++) { if (l[k].i == i) { idx = k; break; } } if (idx >= 0) { if (l[idx].t < 1000000) { l[idx].t += t; if (l[idx].t >= 1000000) { printf("%d\n", i); count++; } } } else { l[j].i = i; l[j].t = t; if (t >= 1000000) { printf("%d\n", i); count++; } } } if (count == 0) { printf("NA\n"); } } return 0; } #include <stdio.h> #include <string.h> #define MAX 1010 int main() { char str[MAX]; int number, strsize; scanf( "%d\n", &number ); for ( int i = 0 ; i < number ; i++ ) { fgets( str, MAX, stdin ); for ( int j = 0 ; str[j] != '\0' ; j++ ) { if ( str[j] == 'H' && str[j+1] == 'o' && str[j+2] == 's' && str[j+3] == 'h' && str[j+4] == 'i' && str[j+5] == 'n' && str[j+6] == 'o' ) { str[j+6] = 'a'; } } printf( "%s", str ); } return 0; } #include<stdio.h> int main(void){ int n,a[10][10]; int sum_line[10],sum_row[10],sum_all; while(1){ scanf("%d",&n); if(n==0) break; for(int i=0;i<10;i++){ sum_line[i]=0; sum_row[i]=0; } sum_all=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ scanf("%d",&a[i][j]); sum_line[i]+=a[i][j]; sum_row[j]+=a[i][j]; sum_all+=a[i][j]; } } for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ if(i==n && j==n)printf("%5d",sum_all); else if(i==n && j!=n)printf("%5d",sum_row[j]); else if(i!=n && j==n)printf("%5d",sum_line[i]); else printf("%5d",a[i][j]); } printf("\n"); } } return 0; } #include<stdio.h> #include<string.h> int main(void) { int n; //イニング数 int k=0; char SET[8]; int sum1[50] = {0}; int sum2 = 0, sum3 = 0; scanf("%d", &n); while(n){ scanf("%s", SET); if(! strcmp(SET, "HIT")){ sum3++; if(sum3 >= 4){ sum1[k]++; sum3--; } }else if(! strcmp(SET,"HOMERUN")){ sum1[k] += sum3; sum1[k]++; sum3 = 0; }else if(! strcmp(SET,"OUT")){ sum2++; } if(sum2 == 3){ sum3 = 0; sum2 = 0; k++; n--; } } for(n = 0; n < k; n++){ printf("%d\n", sum1[n]); } return 0; } #include <stdio.h> #include <string.h> #define MAX 100 #define PGMAX 1001 #define WDMAX 31 typedef struct _index { int pgnum[PGMAX]; int tm; char str[WDMAX]; } index_t; void swap( int i, int j, index_t idx[MAX] ) { char tmp_str[WDMAX]; int tmp_pgnum[PGMAX]; int tmp_tm; strcpy( tmp_str, idx[i].str ); for ( int k = 0 ; k < PGMAX ; k++ ) { tmp_pgnum[k] = idx[i].pgnum[k]; } tmp_tm = idx[i].tm; strcpy( idx[i].str, idx[j].str ); for ( int k = 0 ; k < PGMAX ; k++ ) { idx[i].pgnum[k] = idx[j].pgnum[k]; } idx[i].tm = idx[j].tm; strcpy( idx[j].str, tmp_str ); for ( int k = 0 ; k < PGMAX ; k++ ) { idx[j].pgnum[k] = tmp_pgnum[k]; } idx[j].tm = tmp_tm; } int main() { index_t idx[MAX]; char tmp_str[WDMAX] = {}; int tmp_pgnum = 0, rgnum = 0, i = 0, j = 0, flag = 0, k = 0; while ( scanf( "%s %d", tmp_str, &tmp_pgnum ) != EOF ) { flag = 1; i = 0; while ( i < rgnum ) { if ( strcmp( tmp_str, idx[i].str ) == 0 ) { // BEPO?$5$l$?J8;zNs$NCf$+$i, B:#2sF~NO$5$l$?J8;zNs$,EPO?$5$l$F$$$k$+3NG'$9$k idx[i].pgnum[tmp_pgnum] = 1; idx[i].tm++; flag = 0; // BF~NOJ8;zNs$,EPO?:Q$_$N>l9g break; } i++; } if ( flag ) { // BF~NOJ8;zNs$,EPO?$5$l$F$$$J$$>l9g idx[rgnum].pgnum[tmp_pgnum] = 1; idx[rgnum].tm++; strcpy( idx[rgnum].str, tmp_str ); rgnum++; } } // BF~NOJ8;zNs$N@0Ns$r9T$& for ( i = 0 ; i < rgnum ; i++ ) { for ( j = i+1 ; j < rgnum ; j++ ) { if ( strcmp( idx[i].str, idx[j].str ) > 0 ) { swap( i, j, idx ); } } } // B@0Ns:Q$_$NF~NOJ8;zNs$NG[Ns$KBP$7$F, B=P8=$7$?%Z!<%8HV9f$J$I$r=PNO$9$k for ( i = 0 ; i < rgnum ; i++ ) { printf( "%s\n", idx[i].str ); k = 0; for ( j = 0 ; j < PGMAX ; j++ ) { if ( idx[i].pgnum[j] == 1 ) { if ( k == idx[i].tm-1 ) { printf( "%d\n", j ); break; } else { printf( "%d ", j ); k++; } } } } return 0; } #include <stdio.h> #define MAX 1e+7 int main() { int a, b, c; int n, min_val; int pr_sum, am_sum; while ( scanf( "%d", &n ) == 1 ) { if ( n == 0 ) { break; } // 購入する際のすべての組み合わせを求めて,最安値を求めておく min_val = MAX; for ( a = 0 ; a < 50 ; a++ ) { for ( b = 0 ; b < 50 ; b++ ) { for ( c = 0 ; c < 50 ; c++ ) { pr_sum = ( 380 * ( 5 * (a/5) ) ) * 0.80 + 380 * ( a%5 ); pr_sum += ( 550 * ( 4 * (b/4) ) ) * 0.85 + 550 * ( b%4 ); pr_sum += ( 850 * ( 3 * (c/3) ) ) * 0.88 + 850 * ( c%3 ); if ( 200*a+300*b+500*c == n ) { if ( min_val > pr_sum ) { min_val = pr_sum; } } } } } printf( "%d\n", min_val ); } return 0; } #include <stdio.h> #include <math.h> int main() { double height, width, depth, tmp; double r, r1, r2, r3; int n; while ( scanf( "%lf %lf %lf", &depth, &width, &height ) == 3 ){ if ( depth == 0 && width == 0 && height == 0 ) { break; } scanf( "%d", &n ); for ( int i = 0 ; i < n ; i++ ) { scanf( "%lf", &r ); r1 = sqrt( (depth/2)*(depth/2) + (height/2)*(height/2) ); r2 = sqrt( (width/2)*(width/2) + (height/2)*(height/2) ); r3 = sqrt( (width/2)*(width/2) + (depth/2)*(depth/2) ); if ( r1 < r || r2 < r || r3 < r ) { printf( "OK\n" ); } else { printf( "NA\n" ); } } } return 0; } #include <stdio.h> #define MAX 13 int main() { int n = 0, i = 0, flag = 0, cnt = 0; int numline[MAX] = {}; int tmpline[MAX] = {}; int num[101] = {}; while ( scanf( "%d", &n ) == 1 ) { if ( n == 0 ) { break; } for ( i = 0 ; i < n ; i++ ) { scanf( "%d", &numline[i] ); } flag = 1; cnt = 0; while ( flag ) { // B=P8=J8;zNs$N=i4|2=$r9T$& for ( i = 0 ; i < 101 ; i++ ) { num[i] = 0; } // B=P8=J8;zNs$N%+%&%s%H for ( i = 0 ; i < n ; i++ ) { num[numline[i]]++; } // B=P8=IQEYJ8;zNs$N:n@. for ( i = 0 ; i < n ; i++ ) { tmpline[i] = num[numline[i]]; } cnt++; flag = 0; // numlineB$HtmplineB$NF1$8?tCM?t$r%+%&%s%H // BJ8;zNsD9$H0lCW$9$k>l9g$O, BFs$D$,F1$8G[Ns$G$"$k$3$H$r<($9 for ( i = 0 ; i < n ; i++ ) { if ( tmpline[i] == numline[i] ) { flag++; } } if ( flag == n ) { /*for ( i = 0 ; i < n ; i++ ) { printf( "%3d %3d\n", numline[i], tmpline[i] ); }*/ flag = 0; } else { // B0c$&J8;zNs$N>l9g$O!"<!$NA`:n$KHw$($F?tNs$N%3%T!<$r9T$& for ( i = 0 ; i < n ; i++ ) { numline[i] = tmpline[i]; } flag = 1; } } printf( "%d\n", cnt-1 ); for ( i = 0 ; i < n ; i++ ) { if ( i == n-1 ) { printf( "%d\n", tmpline[i] ); } else { printf( "%d ", tmpline[i] ); } } } return 0; } #include <stdio.h> #include <ctype.h> #define STRMAX 101 int parseerror( char c ); int expression(); int term(); int number(); int factor(); char str[STRMAX] = {}, *tp; int parseerror( char c ) { printf( "[ERROR] Parser cant parse %c\n", c ); return -1; } // B;MB'1i;;$N<0$r%Q!<%9$7$FCM$rJV$9 int expression() { int ret = term(); for ( ; ; ) { if ( *tp == '+' ) { tp++; ret += term(); } else if ( *tp == '-' ) { tp++; ret -= term(); } else { break; } } return ret; } // B>h;;=|;;$N<0$r%Q!<%9$7$FCM$rJV$9 int term() { int ret = factor(); for ( ; ; ) { if ( *tp == '*' ) { tp++; ret *= factor(); } else if ( *tp == '/' ) { tp++; ret /= factor(); } else { break; } } return ret; } // B?t;z$NNs$r%Q!<%9$7$FCM$rJV$9 int number() { int ret = 0; while ( isdigit( *tp ) ) { ret *= 10; ret += *tp - '0'; tp++; } return ret; } // B3g8LIU$-J8;zNs$r%Q!<%9$9$k int factor() { int ret; if ( *tp == '(' ) { tp++; ret = expression(); tp++; // )B$rHt$P$9 } else { ret = number(); } return ret; } int main() { int n; int answer = 0; scanf( "%d\n", &n ); while ( n > 0 ) { fgets( str, 100, stdin ); tp = str; answer = expression(); printf( "%d\n", answer ); n--; } return 0; } #include<stdio.h> #include<string.h> char S[200],A[200],B[200],R[200],C[200],*p; int i,l,N,r; int ch(char x) { return x=='X'?N:x-'0'; } void dfs(int a,int b,int cf,int p) { int t; if(a<0&&b<0) { if(cf)R[p]='1'; return; } else if(a<0||b<0) { t=(a>=0?ch(A[a]):ch(B[b]))+cf; R[p]=t%10+'0'; dfs(a>=0?a-1:a,b>=0?b-1:b,t>9,p+1); } else { t=ch(A[a])+ch(B[b])+cf; R[p]=t%10+'0'; dfs(a-1,b-1,t>9,p+1); } } int main() { for(;gets(S);) { memset(R,0,sizeof(R)); r=-1; p=strtok(S,"+");strcpy(A,p); p=strtok(NULL,"=");strcpy(B,p); p=strtok(NULL,"=");strcpy(C,p); l=strlen(C); for(N=0;N<10;N++) { dfs(strlen(A)-1,strlen(B)-1,0,0); if((N==0&&strlen(A)>1&&strlen(B)>1&&strlen(C)>1&&(A[0]=='X'||B[0]=='X'||C[0]=='X')))continue; if((strlen(R)>1&&R[strlen(R)-1]=='0')||l!=strlen(R))continue; for(i=0;i<l;i++) if(ch(R[i])!=ch(C[l-i-1])) break; if(i==l) { r=N; break; } } if(r==-1)puts("NA"); else printf("%d\n",r); } return 0; } #include <stdio.h> #include <string.h> int main(void) { char after[32][9] = { "100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000", "101", "000000", "000011", "10010001", "010001", "000001" }; char before[32][6] = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111" }; char str[2048], str2[2048]; int i, j, f, len; while (fgets(str, 2048, stdin) != NULL){ for (i = 0; i < 2048; i++){ str2[i] = '\0'; } i = 0; while (str[i] != '\0'){ if (str[i] >= 'A' && str[i] <= 'Z'){ strcat(str2, before[str[i] - 'A']); } switch (str[i]){ case ' ': strcat(str2, before[26]); break; case '.': strcat(str2, before[27]); break; case ',': strcat(str2, before[28]); break; case '-': strcat(str2, before[29]); break; case '\'': strcat(str2, before[30]); break; case '?': strcat(str2, before[31]); break; } i++; } i = 0; while (1){ for (j = 0, f = 0; j < 32; j++){ if (strncmp(&str2[i], after[j], strlen(after[j])) == 0){ f = 1; i += strlen(after[j]); if (j >= 0 && j <= 25){ printf("%c", j + 'A'); } else { switch (j){ case 26: printf(" "); break; case 27: printf("\'"); break; case 28: printf(","); break; case 29: printf("-"); break; case 30: printf("."); break; case 31: printf("?"); break; } } } } if (f == 0){ break; } } puts(""); } return (0); } #include <stdio.h> int main(void) { int num,i,j; while(1){ int guest[10000]={0}; scanf("%d", &num); if(num==0) break; for(i=0; i<num; i++) scanf("%d", &guest[i]); for(i=0; i<num; i++) { for(j=i; j<num; j++) { if(guest[i] > guest[j]) { int tmp = guest[i]; guest[i] = guest[j]; guest[j] = tmp; } } } long sum=0, total=0; for(i=1; i<num; i++) { sum += guest[i-1]; total += sum; } printf("%ld\n", total); } return 0; } #include <stdio.h> int main(void) { int rem[80]; int p, q, i, j, ll, lr; while (scanf("%d%d", &p, &q) == 2) { for (i = 0, ll = -1, lr = -1; i < 80 && p != 0; i++) { for (j = 0; j < i; j++) { if (rem[j] == p) { ll = j; lr = i; goto calcover; } } rem[i] = p; p *= 10; printf("%d", p / q); p = p % q; } calcover:; puts(""); if (ll >= 0) { for (i = 0; i < ll; i++) putc(' ', stdout); for (i = ll; i < lr; i++) putc('^', stdout); puts(""); } } return 0; } #include <stdio.h> long gcd(long a, long b) { if (b == 0){ return (a); } return (gcd(b, a % b)); } long lcm(long a, long b) { return (a / gcd(a, b) * b); } int main(void) { long a1, m1, a2, m2, a3, m3; int x, y, z; int A, B, C; while (1){ scanf("%ld %ld %ld %ld %ld %ld", &a1, &m1, &a2, &m2, &a3, &m3); if (!a1 && !m1 && !a2 && !m2 && !a3 && !m3){ break; } x = a1 % m1; y = a2 % m2; z = a3 % m3; A = 1; while (x != 1){ x = x * a1 % m1; A++; } B = 1; while (y != 1){ y = y * a2 % m2; B++; } C = 1; while (z != 1){ z = z * a3 % m3; C++; } printf("%ld\n", lcm(lcm(A, B), C)); } return (0); } #include<stdio.h> int W,H,i,j,k,t,r; char M[505][505]; int C[505][505]; int main() { for(;scanf("%d%d\n",&H,&W),H;) { r=0; for(i=0;i<H;i++) { gets(M[i]); C[i][0]=M[i][0]=='*'?0:1; for(j=1;j<W;j++) C[i][j]=M[i][j]=='*'?0:C[i][j-1]+1; } for(i=0;i<H;i++) for(j=0;j<W;j++) if(C[i][j]!=0) { t=C[i][j]; for(k=i+1;k<H&&C[k][j]!=0;k++) { t=t>C[k][j]?C[k][j]:t; r=r<(t*(k-i+1))?(t*(k-i+1)):r; } r=r<(t*(k-i))?(t*(k-i)):r; } printf("%d\n",r); } return 0; } #include <stdio.h> #include <string.h> #include <limits.h> #define N 20 #define UL ( INT_MAX >> 1 ) #define MIN(A,B) \ ( (A) < (B) ? (A) : (B) ) static int d[ N ][ N ]; static int n; static int jintan[ N ] = { 0 }; static int FSA ( int p, int t ) { int res = UL; int i; if ( p == t ) return ( 0 ); if ( jintan[ p ] ) return ( UL ); jintan[ p ] = 1; for ( i = 0; i < n; ++i ) { int tmp; if ( d[ p ][ i ] == -1 ) continue ; tmp = FSA ( i, t ) + d[ p ][ i ]; res = MIN( res, tmp ); } jintan[ p ] = 0; return ( res ); } /** Application main entry point. */ int main ( int argc, char * argv[ ] ) { int m, x1, x2, y1, y2; int res; scanf ( "%d %d", &n, &m ); memset ( d, -1, sizeof ( d ) ); while ( m-- ) { int a, b, c1, c2; scanf ( " %d,%d,%d,%d", &a, &b, &c1, &c2 ); d[ a - 1 ][ b - 1 ] = c1; d[ b - 1 ][ a - 1 ] = c2; } scanf ( " %d,%d,%d,%d", &x1, &x2, &y1, &y2 ); res = FSA ( x1 - 1, x2 - 1 ); res += FSA ( x2 - 1, x1 - 1 ); printf ( "%d\n", y1 - y2 - res ); return ( 0 ); } #include <stdio.h> char str[128][128]; int area_id[128][128]; void DFS(int i, int j, int H, int W){ if (i + 1 < H){ if (str[i][j] == str[i+1][j] && area_id[i+1][j] == (i + 1) * W + j){ area_id[i+1][j] = area_id[i][j]; DFS(i + 1, j, H, W); } } if (i - 1 >= 0){ if (str[i][j] == str[i-1][j] && area_id[i-1][j] == (i - 1) * W + j){ area_id[i-1][j] = area_id[i][j]; DFS(i - 1, j, H, W); } } if (j + 1 < W){ if (str[i][j] == str[i][j+1] && area_id[i][j+1] == i * W + (j + 1)){ area_id[i][j+1] = area_id[i][j]; DFS(i, j + 1, H, W); } } if (j - 1 >= 0){ if (str[i][j] == str[i][j-1] && area_id[i][j-1] == i * W + (j - 1)){ area_id[i][j-1] = area_id[i][j]; DFS(i, j - 1, H, W); } } } int main(void) { int H, W, i, j, cnt; char area_num[128 * 128]; while (1){ scanf("%d %d", &H, &W); if (H == 0 && W == 0){ break; } // for (i = 0; i < H; i++){ for (j = 0; j < W; j++){ area_id[i][j] = i * W + j; } } for (i = 0; i < 128 * 128; i++){ area_num[i] = 0; } cnt = 0; // for (i = 0; i < H; i++){ scanf("%s", str[i]); } for (i = 0; i < H; i++){ for (j = 0; j < W; j++){ DFS(i, j, H, W); } } for (i = 0; i < H; i++){ for (j = 0; j < W; j++){ area_num[area_id[i][j]] = 1; } } for (i = 0; i < H; i++){ for (j = 0; j < W; j++){ if (area_num[i * W + j] == 1){ cnt++; } } } printf("%d\n", cnt); } return (0); } #include <stdio.h> #include <string.h> #include <math.h> #define N_MAX 12 #define EPS (1e-7) int width; int n; int r[N_MAX]; double best[N_MAX][1<<N_MAX]; int judge(int prev,int used,double cur_width) { int i; if(best[prev][used]>EPS && cur_width+EPS>best[prev][used])return 0; best[prev][used]=cur_width; if(cur_width>width+EPS)return 0; if(used==(1<<n)-1) { cur_width+=r[prev]; return cur_width<width+EPS; } for(i=0;i<n;i++) { if((used&(1<<i))==0) { /* sqrt((r1+r2)^2 - (r1-r2)^2) */ double delta=2.0*sqrt(r[prev]*r[i]); if(judge(i,used|(1<<i),cur_width+delta))return 1; } } return 0; } int main(void) { char input_buffer[1024]; while(fgets(input_buffer,sizeof(input_buffer),stdin)!=NULL) { int cur_num=0; int cur_index=-1; int i; int ok=0; for(i=0;;i++) { if('0'<=input_buffer[i] && input_buffer[i]<='9') { cur_num=cur_num*10+input_buffer[i]-'0'; } else { if(cur_num>0) { if(cur_index<0)width=cur_num; else r[cur_index]=cur_num; cur_index++; } cur_num=0; if(input_buffer[i]=='\0') { n=cur_index; break; } } } memset(best,0,sizeof(best)); for(i=0;i<n;i++) { ok=ok || judge(i,1<<i,(double)r[i]); } puts(ok?"OK":"NA"); } return 0; }