num

345. 反转字符串中的元音字母

孤人 提交于 2020-02-04 02:57:51
解题思路: 1.先将字符串转成字符数组 2.分别从前后遍历字符数组,如果前后都遍历到了元音字母,就交换两个字符,否则,就继续下一次遍历,直到前后都遍历到了元音字母 3.将字符数组转字符串 代码实现: class Solution { public String reverseVowels(String s) { //元音字母:a,e,i,o,u(区分大小写) int len=s.length(); int i=0;//从前向后遍历 int j=len-1;//从后向前遍历 char[] num=new char[200]; num['a']=1; num['e']=1; num['i']=1; num['o']=1; num['u']=1; num['A']=1; num['E']=1; num['I']=1; num['O']=1; num['U']=1; //字符串转字符数组 char[] arr = s.toCharArray(); while(i<j){ if(num[arr[i]]==0){ i++; continue; } if(num[arr[j]]==0){ j--; continue; } //交换i和j处的字符 char temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; i++; j--; } //字符数组转字符串 s

凯撒加密的简单实现

坚强是说给别人听的谎言 提交于 2020-02-04 02:40:06
凯撒加密的简单实现 def main ( ) : key = input ( "输入密文" ) num = 1 #位移量 out = list ( key ) #输出密文 while num < 26 : num_1 = 0 while num_1 < len ( key ) : if ord ( key [ num_1 ] ) + num < ( ord ( 'z' ) + 1 ) : out [ num_1 ] = chr ( ord ( key [ num_1 ] ) + num ) else : out [ num_1 ] = chr ( ord ( key [ num_1 ] ) + num - 26 ) num_1 = num_1 + 1 num = num + 1 print ( out ) if __name__ == '__main__' : main ( ) 来源: CSDN 作者: weixin_43220691 链接: https://blog.csdn.net/weixin_43220691/article/details/104157151

图神经网络 | (6) 图分类(SAGPool)实战

落爺英雄遲暮 提交于 2020-02-04 02:28:00
近期买了一本图神经网络的入门书,最近几篇博客对书中的一些实战案例进行整理,具体的理论和原理部分可以自行查阅该书,该书购买链接: 《深入浅出的图神经网络》 。 该书配套代码 本节我们通过代码来实现基于自注意力的池化机制(Self-Attention Pooling)。来对图整体进行分类,之前我们是对节点分类,每个节点表示一条数据,学习节点的表示,进而完成分类,本节我们通过自注意力池化机制,得到整个图的表示,进而对全图进行分类(每个图表示一条数据)。 导入必要的包 import os import urllib import torch import torch.nn as nn import torch.nn.init as init import torch.nn.functional as F import torch.utils.data as data import torch.optim as optim import numpy as np import scipy.sparse as sp from zipfile import ZipFile from sklearn.model_selection import train_test_split import pickle import pandas as pd import torch_scatter #注意

小游戏-猜数字

扶醉桌前 提交于 2020-02-04 01:55:14
效果图: 游戏说明: 浏览器随机生成0-100以内的一个数字,在输入框中填写你猜测的数字,猜测范围是0-100以内的正整数哦! 有十次机会猜测,且在这十次猜测中都会对每次的猜测数字进行提示。。 代码 html 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>猜数字小游戏</title> 6 <link rel="stylesheet" href="style.css"> 7 </head> 8 <body> 9 <div class="content start"> 10 <h1>猜数字小游戏</h1> 11 <h4>请在输入框中填写你猜测的数字,猜测范围是0-100以内的正整数哦!</h4> 12 <div class="cont1"> 13 <label for="clientNum"><b>输入数字:</b></label> 14 <input type="text" id="clientNum"> 15 <button>监测</button> 16 <p></p> 17 </div> 18 <div class="cont2"> 19 <b>猜测提示:</b> 20 <span></span> 21 <!-- <span class="info-up"

2020.2.3 随机洗牌程序设计

ぃ、小莉子 提交于 2020-02-04 00:25:15
上机内容:C程序的编写和运行 上机目的:掌握简单C程序的编辑、编译、连接和运行的一般过程 ps:借鉴了同学和网上的思路,感谢。 我的程序: /* * 程序的版权和版本声明部分: * Copyright (c) 2020, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.c * 作 者:容潇军 * 完成日期:2020 年 2 月 3 日 * 版 本 号:v1.0 * 对任务及求解方法的描述部分: * 输入描述:无 * 问题描述:请设计一个随机洗牌系统,将52张除大小王外的扑克随机发给4个人 ,并对每个 人手中的牌进行排序后输出。 排序规则:先按花色排,依次为黑桃、红桃、梅花、方片,同花色的按点数从小到大排。其中,点数A视作点数1。 输出格式:每人占1行,相邻两张牌之间用1个空格分开。 * 程序输出:略 * 问题分析:略 * 算法设计:略 */ #include <iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<memory.h> using namespace std; int main() { bool judge[53];//布尔值判断重复。 int play1[14],play2[14],play3[14],play4[14];//玩家牌。

Codeforces Round #616(Div.2) Array Sharpening

末鹿安然 提交于 2020-02-03 17:32:12
You're given an array a 1 , … , a n a1,…,an of n n non-negative integers. Let's call it sharpened if and only if there exists an integer 1 ≤ k ≤ n 1≤k≤n such that a 1 < a 2 < … < a k a1<a2<…<ak and a k > a k + 1 > … > a n ak>ak+1>…>an. In particular, any strictly increasing or strictly decreasing array is sharpened. For example: The arrays [ 4 ] [4], [ 0 , 1 ] [0,1], [ 12 , 10 , 8 ] [12,10,8] and [ 3 , 11 , 15 , 9 , 7 , 4 ] [3,11,15,9,7,4] are sharpened; The arrays [ 2 , 8 , 2 , 8 , 6 , 5 ] [2,8,2,8,6,5], [ 0 , 1 , 1 , 0 ] [0,1,1,0] and [ 2 , 5 , 6 , 9 , 8 , 8 ] [2,5,6,9,8,8] are not sharpened

【算法题】CCF CSP第三题练习

烈酒焚心 提交于 2020-02-03 15:44:55
样例全部没问题,但是只有40分,不知道哪里出问题了: #include <iostream> #include <string> #include <map> #include <sstream> using namespace std; class Fomular { private: string s, sr, sp; map<string,int> reactant; map<string,int> product; map<string,int> rElement; map<string,int> pElement; bool isLowercase(char a) { if (a >= 'a' && a <= 'z') return true; return false; } bool isUppercase(char a) { if (a >= 'A' && a <= 'Z') return true; return false; } bool isDigit(char a) { if (a >= '0' && a <= '9') return true; return false; } void split(string s, decltype(product) &m) { int a{0}, b{0}, i, j, tt; string t; for (i = 0;

「NOIP 2017」列队

╄→尐↘猪︶ㄣ 提交于 2020-02-03 15:42:32
题目大意:给定一个 $n times m$ 的方阵,初始时第 $i$ 行第 $j$ 列的人的编号为 $(i-1) times m + j$,$q$ 次给出 $x,y$,让第 $x$ 行 $y$ 列的人出队,然后其他人先向左看齐,后向前看齐,再把出队的人放在第 $n$ 行 $m$ 列,请你输出每次出队的人的编号。$n,m,q leq 3 times 10^5$ 对于 $n,m leq 50000, q leq 500$ 的数据,可以离散化,但是不能用 map,因为 map 的所有操作都是带 log 的。 考虑 $q leq 500$,即最多涉及到 $500$ 个行,于是可以将行离散化,开一个 $500 times 50000$ 的数组,最后一列单独开一个 $50000 times 1$ 的数组。 对于所有 $x=1$ 的数据,可以用 treap,注意在 maintain 函数中所加的是 $1$ 而不是 $num[cur]$ 时,一定要加上 $cur neq 0$ 的判断。 (顺便提一下线段树做法:用 $0,1$ 表示该位置有没有人,初始时 $1 cdots n+m-1$ 的位置都是 $1$,每删一个元素就把它变成 $0$,把它新插入的位置变成 $1$,查询第 $i$ 个元素就是查询前缀和等于 $i$ 的位置) #include <cstdio> #include <cstdlib>

Python试题汇总

随声附和 提交于 2020-02-03 15:40:02
说明:以下是我学习整理的有关Python的相关笔试或者面试题,因为题目是自己解答的,如有错误,欢迎指出! 2018-09-06 1.简述函数式编程   答:在函数式编程中,函数是基本单位,变量只是一个名称,而不是一个存储单元。除了匿名函数外,Python还使用fliter(),map(),reduce(),apply()函数来支持函数式编程。 2.什么是匿名函数,匿名函数有什么局限性   答:匿名函数,也就是lambda函数,通常用在函数体比较简单的函数上。匿名函数顾名思义就是函数没有名字,因此不用担心函数名冲突。不过Python对匿名函数的支持有限,只有一些简单的情况下可以使用匿名函数。 3.如何捕获异常,常用的异常机制有哪些?   答:如果我们没有对异常进行任何预防,那么在程序执行的过程中发生异常,就会中断程序,调用python默认的异常处理器,并在终端输出异常信息。   ①try...except...finally语句:当try语句执行时发生异常,回到try语句层,寻找后面是否有except语句。找到except语句后,会调用这个自定义的异常处理器。except将异常处理完毕后,程序继续往下执行。finally语句表示,无论异常发生与否,finally中的语句都要执行。   ②assert语句:判断assert后面紧跟的语句是True还是False

猜数字

你说的曾经没有我的故事 提交于 2020-02-03 14:10:49
/* 程序的版权和版本声明部分: Copyright (c) 2013, 烟台大学计算机学院 All rights reserved. 文件名称:test.cpp 作 者:赵加响 完成日期:2013 年 11 月 14 日 版 本 号:v1.0 对任务及求解方法的描述部分: 输入描述:无 问题描述:猜数字 程序输出: 问题分析:略 算法设计:略 */ #include <iostream> #include<ctime> #include <cstdlib> using namespace std; int main (void) { int n,num,count=0; srand(time(0));//time(0)作为返回值种子 num=rand()%1000;//定义该数字为1000之内的任意一数字 do { cout<<"猜一个数"; cin>>n; if(n==num) break; else if(n>num) cout<<"大了"<<endl; else cout<<"小了"<<endl; count++; } while(true); cout<<"经历了"<<count<<"次,猜对了!"<<endl; return 0; } 心得体会:对其中的一些语言还是不熟悉,还应加强对其的学习。 来源: https://www.cnblogs.com/riskyer/p