c++中的常见问题

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;
} 
*/

前车之覆,后车之鉴!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值