#includebitsstdc++husing namespace std;__int128 abans;int c;inline __int128 read __int128 x=0;int f=1; char c=getchar; while!isdigitc ifc==- f=-1c=getchar; whileisdigitc x=x3+x1+c^48c=getchar; return
这段代码中存在一个问题,即在读取答案时使用了read()函数,这会导致无法手动输入答案。解决这个问题的方法是使用cin来读取答案,而不是使用read()函数。
修改代码如下:
#include<bits/stdc++.h>
using namespace std;
__int128 a,b,ans;
int c;
inline __int128 read(){
__int128 x=0;
int f=1;
char c=getchar();
while(!isdigit(c)) if(c=='-') f=-1,c=getchar();
while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x*f;
}
void write(__int128 x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10|'0');
}
int main(){
while(puts("Please press the 0 and the enter key to end the game and press the 1 or 2 and press the enter key to select the mode."),scanf("%d",&c),c){
srand(time(nullptr));
if(c!=1&&c!=2){
puts("The key which is pressed isn't the 1 or 2.");
return 0;
}
switch(c){
case 1:
a=rand()%1145+1;
b=rand()%1145+1;
write(a);
putchar('*');
write(b);
puts("=?");
cin >> ans; // 使用cin读取答案
if(ans==a*b) puts("You are clever.");
else puts("RUSB?");
case 2:
a=rand()%25+1;
b=rand()%25+1;
write(a);
putchar('^');
write(b);
puts("=?");
cin >> ans; // 使用cin读取答案
if(ans==__int128(pow(a,b))) cout<<"You are clever.\n";
else cout<<"RUSB?\n";
}
}
return 0;
}
这样修改后,每次答题时可以手动输入答案
原文地址: http://www.cveoy.top/t/topic/id1D 著作权归作者所有。请勿转载和采集!