AxxxxxxxxxxxxxxxxxxxxAxxxxxxxxBxxxxxxxxCxxxxCxxxxAxxBxxxxAxCxB
56, 60 지역에서 발생. 거리는 4
#include <stdio.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <vector> using namespace std; struct term { int term; int proxy; }; int distance(int a, int b, int c, int *amax, int *amin); int main(int argc, char **argv) { char str[]="AxxxxxxxxxxxxxxxxxxxxxxAxxxBxxxxxAxxxxCxxxxxxCxAxxxxBxxxCxxxAxBxCx"; int i = 0; vector<struct term> post; vector<struct term>::iterator mi; int min_dist = 10000; int dist = 0; int max, min; int upper, lower; struct term termp; for(i = 0; i < strlen(str); i++) { switch(str[i]) { case 'A': termp.term = 'A'; termp.proxy = i+1; post.push_back(termp); break; case 'B': termp.term = 'B'; termp.proxy = i+1; post.push_back(termp); break; case 'C': termp.term = 'C'; termp.proxy = i+1; post.push_back(termp); break; } } printf(" 1 2 3 4 5 6 7 8 9\n"); printf("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n"); printf("%s\n", str); mi = post.begin(); struct term mask[3]; memset(mask, 0x00, sizeof(term)*3); while(mi != post.end()) { mask[mi->term-65] = *mi; if(mask[0].proxy && mask[1].proxy && mask[2].proxy) { dist = distance(mask[0].proxy, mask[1].proxy, mask[2].proxy, &upper, &lower); if(dist < min_dist) { min_dist = dist; max = upper; min = lower; } } mi++; } printf("%d,%d에 있고 거리는 %d이다.\n", min, max, min_dist); return 1; } int distance(int a, int b, int c, int *amax, int *amin) { int min=0; int max=0; if(a > b) { max = a; min = b; } else { max = b; min = a; } if(max < c) { max = c; } if(min > c) { min = c; } *amax = max; *amin = min; return max-min; }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
소개
문제
문제 풀이
yundream의 풀이
Recent Posts
Archive Posts
Tags