ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

c++ code:(2)function

2019-05-17 20:50:17  阅读:303  来源: 互联网

标签:function tmp code int EPS c++ %. x2 include


#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define EPS 1e-7
int main()
{
	double a,b,c; //不要用 float,精度不够
	scanf("%lf%lf%lf",&a,&b,&c);
	double tmp = b*b - 4*a*c;
	if( tmp < EPS && tmp > - EPS)
		printf("x1=x2=%.5f",(-b)/(2*a)+EPS);  // + EPS是为了防止出现 -0.00000 
	else if( tmp > EPS) {
		double x1 = (-b+sqrt(tmp))/(2*a);
		double x2 = (-b-sqrt(tmp))/(2*a)+EPS;
		if( x1 - x2 > EPS)
			printf("x1=%.5f;x2=%.5f",x1+EPS,x2+EPS);
		else
			printf("x1=%.5f;x2=%.5f",x2+EPS,x1+EPS);
	}
	else {
		
		printf("x1=%.5f+%.5fi;x2=%.5f-%.5fi",(-b)/(2*a)+EPS,sqrt(-tmp)/(2*a)+EPS,(-b)/(2*a)+EPS,sqrt(-tmp)/(2*a)+EPS);
	}
	return 0;
}

 

#include <iostream>
//#include <iomanip>
#include <cstdio>
using namespace std;
const int MX = 110;
short a[MX][MX];  //0-255 so 采用short
short b[MX][MX];
int main()
{
	freopen("f:\\MOOC c++\\week5\\8167.txt", "r", stdin);
	int n,m;
	cin >> n >> m;
	for(int i = 1;i <= n; ++i)
		for(int j = 1; j <= m; ++j )  {
			cin >> a[i][j];
			b[i][j] = a[i][j];
		}
	for(int i = 1;i <= n; ++i)
		for(int j = 1; j <= m; ++j ) {
			if( i > 1 && i < n && j > 1 && j < m) {
				int sum = a[i][j] + a[i-1][j] + a[i+1][j]+a[i][j-1]+a[i][j+1];
				int v = sum / 5;
				//rounding ~~~~
				double f = (double)sum / 5;
				if( f - v - 0.5 > 1e-6)
					++v;

				b[i][j] = v;
			}
		}
	for(int i = 1;i <= n; ++i) {
		for(int j = 1; j <= m; ++j ) 
			cout << b[i][j] << " ";
		cout << endl;
	}
	return 0;
}

#include<iostream>
using namespace std;

int gcd(int a, int b)
{
	if (a % b == 0)
		return b;
	return gcd(b,a%b);
}

int main()
{
	freopen("f:\\freopen.txt", "r", stdin);
	int x, y;
	cin >> x >> y;
	cout << gcd(y, x) << endl;
	return 0;
}

 

#include <iostream>
using namespace std;
int bitManipulation1(int n, int m, int i) {
	return ((n&~(1<<i))|((m>>i)&1)<<i);
}
int main() {
	freopen("f:\\freopen.txt", "r", stdin);
	int n, m, i, t;
	cin >> t;
	while (t--) {
		cin >> n >> m >> i;
		cout << bitManipulation1(n, m, i) << endl;
	}
	return 0;
}

 

 

#include <iostream>
using namespace std;

int bitManipulation2(int n, int i) {
	return (n&~(1 << i))&(~(((n >> i) & 1) << i));
	return n ^ (~0 << (32 - i));
}

int main() {
	freopen("f:\\freopen.txt", "r", stdin);
	int t, n, i;
	cin >> t;
	while (t--) {
		cin >> n >> i;
		cout << bitManipulation2(n, i) << endl;
	}
	return 0;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

标签:function,tmp,code,int,EPS,c++,%.,x2,include
来源: https://blog.csdn.net/Bluenapa/article/details/89818733

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有