※本題為互動題
Ststone參加了一個猜數字大賽,已知數字的範圍介在1~107之間,每次他猜了一個數字,主持人會回答他1或0,1代表他猜的數字大於等於答案,0則是代表他猜的數字小於答案。
由於疫情的緣故,今年的猜數字大賽改成線上舉辦,主辦單位為了減少人力,寫了一個主持程式,分別有兩個函式可以使用。
C++:請複製以下程式碼,貼在main外,並在main裡面,先呼叫cpp_start();函式再繼續作答。建議使用long long及cin cout作答。
long long st_ans1=0,st_ans2=0,st_com=0,st_cnt=0;template<typename stst>stst request(stst a){st_cnt++;if(st_com==1)std::cout << "request=qwertyuiopasdfghjklzxcvbnm;check=ok;waiting_for_the_answer;next_line=check;reading=false;check_point=false\n";if(a>=st_ans2-st_ans1) return 1ll;else return 0ll;}template<typename stst>void upload_answer(stst a){if(st_com==1){std::cout<<"request=mnbvcxzlkjhgfdsapoiuytrewq;check=ok;waiting_for_the_answer;next_line=answer;reading=true;check_point=true\n";std::cout <<1000000007+5*(4*a+3) << '\n';}if(a==st_ans2-st_ans1){std::cout << "AC\n";std::cout << "request: "<<st_cnt<<" times.";}else{std::cout << "WA\n";std::cout << "Your answer is: "<<a<<".\n";std::cout << "request: "<<st_cnt<<" times.";}}void cpp_start(){long long st_cc;std::cin>>st_cc;if(st_cc==-87) st_com=1;if(st_com==1){long long Do_not_change_it_plz,ststone,st_zerojudge,st_IDK,st_hard,st_mouse,st_check;std::cin>>Do_not_change_it_plz>>ststone>>st_zerojudge>>st_IDK>>st_hard>>st_mouse>>st_check;st_ans1=Do_not_change_it_plz+ststone-st_zerojudge-st_IDK+st_hard-st_mouse;st_ans2=st_ans1*st_check;}else st_ans2 = st_cc;}
Python:請複製以下程式碼,貼在第一行。
st_cc = int(input());st_com=0;st_cnt=0;st_com=1 if st_cc==-87 else 0;Do_not_change_it_plz = int(input()) if st_com else 0;ststone = int(input()) if st_com else 0;st_zerojudge = int(input()) if st_com else 0;st_IDK = int(input()) if st_com else 0;st_hard = int(input()) if st_com else 0;st_mouse = int(input()) if st_com else 0;st_check = int(input()) if st_com else 0;st_ans1=Do_not_change_it_plz+ststone-st_zerojudge-st_IDK+st_hard-st_mouse;st_ans2=st_ans1*st_check if st_com else st_cc;st_qwertyuiopasdfghjklzxcvbnm_st=st_ans2-st_ans1
def request(a:int):global st_cnt,st_com;st_cnt +=1;print("request=qwertyuiopasdfghjklzxcvbnm;check=ok;waiting_for_the_answer;next_line=check;reading=false;check_point=false")if st_com else print("",end=""); return a>=int(st_ans2-st_ans1) if 1 else 0
def upload_answer(a:int):global st_cnt,st_com;print("request=mnbvcxzlkjhgfdsapoiuytrewq;check=ok;waiting_for_the_answer;next_line=answer;reading=true;check_point=true")if st_com else print("",end="");print(1000000007+5*(4*a+3)) if st_com else print("",end="");print("AC\nrequest: "+str(st_cnt)+" times.") if int(a)==int(st_ans2-st_ans1) else print("WA\nYour answer is: "+str(a)+".\nrequest: "+str(st_cnt)+" times.")
long long st_ans1=0,st_ans2=0,st_com=0,st_cnt=0,st_cc;long long request(long long a){st_cnt++;if(st_com==1)printf("%s\n","request=qwertyuiopasdfghjklzxcvbnm;check=ok;waiting_for_the_answer;next_line=check;reading=false;check_point=false");if(a>=st_ans2-st_ans1) return 1;else return 0;}void upload_answer(long long a){if(st_com==1){printf("%s\n","request=mnbvcxzlkjhgfdsapoiuytrewq;check=ok;waiting_for_the_answer;next_line=answer;reading=true;check_point=true");printf("%lld\n",1000000007+5*(4*a+3));}if(a==st_ans2-st_ans1){printf("%s\n","AC");printf("%s %lld %s\n","request: ",st_cnt," times.");}else{printf("%s\n","WA");printf("%s %lld %s\n","Your answer is: ",a,".");printf("%s %lld %s\n","request: ",st_cnt," times.");}}void c_start(){scanf("%lld",&st_cc);if(st_cc==-87){st_com=1;}if(st_com==1){long long Do_not_change_it_plz,ststone,st_zerojudge,st_IDK,st_hard,st_mouse,st_check;scanf("%lld%lld%lld%lld%lld%lld%lld",&Do_not_change_it_plz,&ststone,&st_zerojudge,&st_IDK,&st_hard,&st_mouse,&st_check);st_ans1=Do_not_change_it_plz+ststone-st_zerojudge-st_IDK+st_hard-st_mouse;st_ans2=st_ans1*st_check;}else st_ans2 = st_cc;}
static long st_ans1=0,st_ans2=0,st_com=0,st_cnt=0;static Scanner scanner = new Scanner(System.in);public static long request(long a){st_cnt++;if(st_com==1)System.out.println("request=qwertyuiopasdfghjklzxcvbnm;check=ok;waiting_for_the_answer;next_line=check;reading=false;check_point=false");if(a>=st_ans2-st_ans1) return 1;else return 0;}public static void upload_answer(long a){if(st_com==1){System.out.println("request=mnbvcxzlkjhgfdsapoiuytrewq;check=ok;waiting_for_the_answer;next_line=answer;reading=true;check_point=true");System.out.println(1000000007+5*(4*a+3));}if(a==st_ans2-st_ans1){System.out.println("AC");System.out.println("request: "+st_cnt+" times.");}else{System.out.println("WA");System.out.println("Your answer is: "+a+".");System.out.println("request: "+st_cnt+" times.");}}public static void java_start(){long st_cc;st_cc = scanner.nextLong();if(st_cc==-87)st_com=1;if(st_com==1){long Do_not_change_it_plz = scanner.nextLong(),ststone = scanner.nextLong(),st_zerojudge = scanner.nextLong(),st_IDK = scanner.nextLong(),st_hard = scanner.nextLong(),st_mouse = scanner.nextLong(),st_check = scanner.nextLong();st_ans1=Do_not_change_it_plz+ststone-st_zerojudge-st_IDK+st_hard-st_mouse;st_ans2=st_ans1*st_check;}else st_ans2 = st_cc;}
於使用者端測試時,請輸入一個整數A(1≤A≤107),並且最後使用upload_answer(a)回傳答案,程式會幫你判斷你所回傳的答案是否為輸入的數字。
若輸入的數字與upload_answer(a)回傳的數字相等時:
AC
request: X times.
不相等時:
WA
Your answer is: OOO.
request: X times.
OOO與X會依照實際情形變化
100
回傳100: AC request: 24 times. 回傳101: WA Your answer is: 101. request: 24 times.
87
回傳87: AC request: 24 times. 回傳78: WA Your answer is: 78. request: 24 times.
目前公開測試中。
有問題歡迎詢問或來信。
編號 | 身分 | 題目 | 主題 | 人氣 | 發表日期 |
沒有發現任何「解題報告」
|