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

香港网站怎么做QQ第三方登录百度搜索网址大全

香港网站怎么做QQ第三方登录,百度搜索网址大全,直销网站建设,微信官方免费下载前言 最近需要开始使用python,但是对python了解的并不多,于是先从很早之前刚学C时写过的一些练手题开始,使用python来实现相同的功能,在温习python基础语法的同时,也一起来感受感受python的魅力 99乘法表 c&#xf…

前言

最近需要开始使用python,但是对python了解的并不多,于是先从很早之前刚学C++时写过的一些练手题开始,使用python来实现相同的功能,在温习python基础语法的同时,也一起来感受感受python的魅力

99乘法表

c++:

#include<iostream>
int main()
{int i,j;for (i = 1; i <= 9; i++){for (j = 1; j <= i; j++)std::cout <<j<<"*"<<i <<"=" << i * j << "  ";std::cout << '\n';}
}

python:

for lie in range(1, 10):for hang in range(1, lie + 1):print(f"{hang}*{lie}={hang * lie}", end="  ")print()  # 打印空行

素数

c++

#include<iostream>
int judge(int ,bool);
int main()
{int n;std::cout << "请输入数字n,判断其是否为素数" << '\n' << "n=";std::cin >> n;bool flage = true;if (judge(n,flage) == false) std::cout << n<<"不是素数";else if (judge(n,flage) == true) std::cout << n<<"是素数";
}
int judge(int n, bool flage)
{for (int i = 2; i <= sqrt(n); i++){if ((n % i) == 0){flage = false;break;}}return flage;
}

python:

import mathn = int(input('请输入数字n,判断其是否为素数\nn='))
Is_SuShu = True
for i in range(2, int(math.sqrt(n))):if n % i == 0:Is_SuShu = Falsebreak
if Is_SuShu:print(f'{n}是素数')
else:print(f'{n}不是素数')

水仙花数

c++:

#include<iostream>//水仙花数:各位数字的立方相加等于其本身
//如果三位数的话,就是个位数的立方加上十位数的立方加上百位数的立方等于其本身的数,就叫水仙花数
int main()//求100到999内的所有水仙花数
{int i = 100;int ge, shi, bai;do {ge = i % 10;shi = (i % 100) / 10;bai = (i % 1000) / 100;if (ge * ge * ge + shi * shi * shi + bai * bai * bai == i)std::cout << i << '\n';i++;} while (i <= 999);
return 0;
}

python:

for i in range(100, 999):bai_wei = int(i / 100 % 10)shi_wei = int(i / 10 % 10)ge_wei = int(i / 1 % 10)if bai_wei ** 3 + shi_wei ** 3 + ge_wei ** 3 == i:print(i)

括号匹配

#include<iostream>
#include<string>
#include<stack>
static bool Is_righ(std::string In_str);int main()
{std::string In_str;std::cout << "请输入一个表达式 :";//如:{{([])}}std::cin >> In_str;if (Is_righ(In_str)) {std::cout << "括号匹配";}else {std::cout << "括号不匹配";}
}
static bool Is_righ(std::string In_str) {std::stack<char> st;bool check = true;for (int i = 0; i < In_str.length(); i++) {switch (In_str[i]) {case '(': {st.push('('); break;}case '[': {st.push('['); break;}case '{': {st.push('{'); break;}case ')': {if (st.top() == '(')st.pop();else {check = false;break;}break;}case ']': {if (st.top() == '[')st.pop();else {check = false;break;}break;}case '}': {if (st.top() == '{')st.pop();else {check = false;break;}break;}default:break;}}if (st.empty() && check)return true;elsereturn false;
}

python:

st = []
In_str = input("请输入一个表达式:")  # 如{()[]}Is_ok = True
for i in In_str:if i == '(':st.append('(')elif i == '[':st.append('[')elif i == '{':st.append('{')elif i == ')':if st[-1] == '(':st.pop()else:Is_ok = Falsebreakelif i == ']':if st[-1] == '[':st.pop()else:Is_ok = Falsebreakelif i == '}':if st[-1] == '{':st.pop()else:Is_ok = Falsebreakif st is None and Is_ok:print('括号匹配', end="")
else:print('括号不匹配', end="")

python整体比C++要简介的多,当然使用python完成C++的练习题肯定也不能完全体现python的优势。

http://www.hkea.cn/news/717239/

相关文章:

  • 中国工程局人才招聘网福建seo推广方案
  • 深圳南山做网站的公司百度投诉中心
  • 辽宁建设工程信息网业绩认定武汉网站优化公司
  • 莱芜都市人才网上海网站seo公司
  • 广州做鞋的网站怎么让某个关键词排名上去
  • 温州平阳县网站建设兼职东莞网络推广哪家公司奿
  • 做单页网站价格微信朋友圈广告在哪里做
  • 濮阳家电网站建设一般开车用什么导航最好
  • html5 图片展示网站大作设计网站
  • 河北正规网站建设比较百度一下你就知道官页
  • 企业网站建设哪家服务好福州网站关键词推广
  • 惠州悦商做网站软件开发一般需要多少钱
  • 做衣服外单网站优化大师官方正版下载
  • 专门做酒店的网站百度排行
  • 上海做手机网站建设盐城网站优化
  • html论坛模板东营seo整站优化
  • 天津网站建设582345网址导航桌面版
  • 东莞纸箱厂东莞网站建设经典模板网站建设
  • 贺州同城购物网站建设中国网站排名100
  • 黄骅港旅游景点爱站网seo工具包
  • 网站 图文混编提高网站搜索排名
  • 北京怀柔网站制作教育机构
  • 网站建设费 大创友链交换平台
  • o2o商城网站系统开发微信群拉人的营销方法
  • 帝国cms做淘宝客网站网页设计用什么软件
  • 营销型网站建设的优缺点视频优化软件
  • 珠海响应式网站建设推广公司网络营销发展方案策划书
  • 中国人自己的空间站每日英语新闻
  • 教师可以做网站吗seo常用工具包括
  • 武山建设局网站什么是seo