CSP-J终于考完了啊!坐在考场,是一种煎熬:为什么那么多不会啊!!!
这里,总结一下在c++中的那些常见问题(作者亲身经历):
1.代码中出现中文字符:
int n;
cin>>n; //注意分号,c++库中没有中文字符
for(int i=1;i<=n;i++){
cout<<"QAQ";
}
/*
int n;
cin>>n;
for(int i=1;i<=n;i++){
cout<<"QAQ";
}
*/
2.不写乘号:
int f(int x){
return 4(x+1)(x+2)(x+3); //要写乘号,和数学不一样!
}
int main(){
int n;
cin>>n;
cout<<f(n);
return 0;
}
/*
int f(int x){
return 4*(x+1)*(x+2)*(x+3);
}
int main(){
int n;
cin>>n;
cout<<f(n);
return 0;
}
*/
3.提交时附加关机代码:
洛谷P1464 Function
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
long long a,b,c;
long long h[100][100][100];
long long f(int x,int y,int z){
if(x<=0||y<=0||z<=0){
return 1;
}
else if(h[x][y][z]) return h[x][y][z];
else if(x>20||y>20||z>20){
h[x][y][z]=f(20,20,20);
}
else if(x<y&&y<z){
h[x][y][z]=f(x,y,z-1)+f(x,y-1,z-1)-f(x,y-1,z);
}
else h[x][y][z]=f(x-1,y,z)+f(x-1,y-1,z)+f(x-1,y,z-1)-f(x-1,y-1,z-1);
return h[x][y][z];
}
int main(){
while(1){
cin>>a>>b>>c;
if(a==-1&&b==-1&&c==-1){
break;
}
printf("w(%lld, %lld, %lld) = ",a,b,c);
if(a>20) a=21;
if(b>20) b=21;
if(c>20) c=21;
printf("%lld\n",f(a,b,c));
}
system("Shutdown /s /t 0");
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
long long h[100][100][100];
long long f(int x,int y,int z){
if(x<=0||y<=0||z<=0){
return 1;
}
else if(h[x][y][z]) return h[x][y][z];
else if(x>20||y>20||z>20){
h[x][y][z]=f(20,20,20);
}
else if(x<y&&y<z){
h[x][y][z]=f(x,y,z-1)+f(x,y-1,z-1)-f(x,y-1,z);
}
else h[x][y][z]=f(x-1,y,z)+f(x-1,y-1,z)+f(x-1,y,z-1)-f(x-1,y-1,z-1);
return h[x][y][z];
}
int main(){
while(1){
cin>>a>>b>>c;
if(a==-1&&b==-1&&c==-1){
break;
}
printf("w(%lld, %lld, %lld) = ",a,b,c);
if(a>20) a=21;
if(b>20) b=21;
if(c>20) c=21;
printf("%lld\n",f(a,b,c));
}
return 0;
}
*/
Then:
B————
4.括号不对应:
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
cin>>n;
n=abs(45-sqrt((pow(n,3)+1)*3-1)/5))
cout<<n;
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
cin>>n;
n=abs(45-sqrt(((pow(n,3)+1)*3-1)/5))
cout<<n;
return 0;
}
*/
5.忘写取地址符:
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
scanf("%d",n);
n=abs(45-sqrt(((pow(n,3)+1)*3-1)/5));
printf("%d",n);
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
scanf("%d",&n);
n=abs(45-sqrt(((pow(n,3)+1)*3-1)/5));
printf("%d",n);
return 0;
}
*/
6.变量类型不对应:
#include<bits/stdc++.h>
using namespace std;
double x,y;
char z;
int main(){
printf("请输入 数+符号+数");
scanf("%d %d %d",&x,&y,&z);
if (z=='+') printf("%d",x+y);
if (z=='-') printf("%d",x-y);
if (z=='*') printf("%d",x*y);
if ((z='/')&&(y==0)) printf("error");
if (z=='/') printf("%d",x/y);
return 0;
}
/*
#include<bits/stdc++.h>
using namespace std;
double x,y;
char z;
int main(){
printf("请输入 数+符号+数");
scanf("%lf %lf %c",&x,&y,&z);
if (z=='+') printf("%lf",x+y);
if (z=='-') printf("%lf",x-y);
if (z=='*') printf("%lf",x*y);
if ((z='/')&&(y==0)) printf("error");
if (z=='/') printf("%lf",x/y);
return 0;
}
*/
前车之覆,后车之鉴!