当前位置: 首页 > news >正文

c++ code:(2)function

#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;
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

相关文章:

  • c++ code:(4)pointer
  • c++ code:(5)sort
  • code 练习之路
  • 初见kopernio
  • c++ code:(7)basics2
  • c++ code:(10)operator overload
  • c++ code:(11)inheritance
  • c++ code:(12)polymorphism
  • c++ code:(13)io and template
  • 英文论文写作素材
  • 王梓坤院士的学术思想
  • 使用EI、SCI搜索 (使用 websci中的endnote online引用 )
  • 玩转word 和 mathtype 的结合
  • paper 格式
  • 计算思维
  • 【跃迁之路】【641天】程序员高效学习方法论探索系列(实验阶段398-2018.11.14)...
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • Java|序列化异常StreamCorruptedException的解决方法
  • Javascript 原型链
  • nfs客户端进程变D,延伸linux的lock
  • Node 版本管理
  • Python进阶细节
  • Python连接Oracle
  • React 快速上手 - 07 前端路由 react-router
  • Spark VS Hadoop:两大大数据分析系统深度解读
  • Sublime text 3 3103 注册码
  • vuex 笔记整理
  • 纯 javascript 半自动式下滑一定高度,导航栏固定
  • 分布式任务队列Celery
  • 浮现式设计
  • 湖南卫视:中国白领因网络偷菜成当代最寂寞的人?
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 让你的分享飞起来——极光推出社会化分享组件
  • 如何使用Mybatis第三方插件--PageHelper实现分页操作
  • 温故知新之javascript面向对象
  • 小程序开发之路(一)
  • 延迟脚本的方式
  • Android开发者必备:推荐一款助力开发的开源APP
  • 扩展资源服务器解决oauth2 性能瓶颈
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • (1)虚拟机的安装与使用,linux系统安装
  • (附源码)springboot宠物医疗服务网站 毕业设计688413
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (强烈推荐)移动端音视频从零到上手(下)
  • (三十五)大数据实战——Superset可视化平台搭建
  • (算法二)滑动窗口
  • (译) 理解 Elixir 中的宏 Macro, 第四部分:深入化
  • (转)shell中括号的特殊用法 linux if多条件判断
  • (转)为C# Windows服务添加安装程序
  • (轉貼) 寄發紅帖基本原則(教育部禮儀司頒布) (雜項)
  • .NET Remoting学习笔记(三)信道
  • .net 反编译_.net反编译的相关问题
  • .net 开发怎么实现前后端分离_前后端分离:分离式开发和一体式发布