A. Bear and Prime 100
题目很简单,就是交互题是第一次写,
交互题相当于是每一次读入用一次fflush(stdout)?
反正就这么a掉了。
关于strcmp,字符串相同为 0 , 不同为 1
c++代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<queue> #include<stack> #include<map> #include<set> #include<iostream> #include<algorithm> #include<string> #define rep(i,x,y) for(register int i = x;i <= y;++i) #define repd(i,x,y) for(register int i = x;i >= y;--i) using namespace std; typedef long long ll; template<typename T>void read(T&x) { x = 0;char c;int sign = 1; do { c = getchar();if(c == '-') sign = -1; }while(c < '0' || c > '9'); do { x = x * 10 + c - '0'; c = getchar(); }while(c <= '9' && c >= '0'); x *= sign; } int phi[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,4,9,25,49}; int cnt; char s[5]; int main() { rep(i,0,18) { printf("%d ",phi[i]); fflush(stdout); scanf("%s",s); if(strcmp(s,"no")) cnt++; if(cnt >= 2) break; } if(cnt >= 2) puts("composite"); else puts("prime"); return 0; } |