这是我写的:
#include <iostream>
using namespace std;
struct vetura{
char ngjyra[10];
char tipi[10];
};
int main(){
int i,j;
vetura v[4];
for(i=0;i<4;i++){
cout << "Ngjyra:"<<endl;
cin >> v[i].ngjyra;
cout << "tipi:"<<endl;
cin >> v[i].tipi;
}
j=0;
for(i=0;i<4;i++){
if(v[i].ngjyra == "kuqe" && v[i].tipi == "passat")
j+1;
}
cout<<"kemi "<<j<<" vetura passat me ngjyre te kuqe";
cin.get();cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我需要计算我为v [i] .ngjyra写了"kuqe"的次数和v [i] .tipi的"passat".我认为变量j每次都会变得越来越大但是它不起作用我将在接下来的几个小时进行考试可以有人帮助我吗?
所以我在Ubuntu上使用zlib包.我正在试图弄清楚如何正确使用gzopen和gzread,这是我到目前为止所拥有的
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <zlib.h>
#define NUM_BUFFERS 8
#define BUFFER_LENGTH 1024
char buf[BUFFER_LENGTH];
int main(int argc, const char* argv[])
{
int status;
gzFile file;
file = gzopen("beowulf.txt", "w");
int counter = 0; /*when the counter reachers BUFFERS_FULL, stop*/
if(file == NULL)
{
printf("COULD NOT OPEN FILE\n");
return 1;
}
while(counter < NUM_BUFFERS)
{
status = gzread(file, buf, BUFFER_LENGTH - 2);
printf("STATUS: %d\n", status);
buf[BUFFER_LENGTH - 1] = "\0";
printf("%s\n", buf);
counter++;
}
gzclose(file);
printf("STATUS: %d\n", status); …Run Code Online (Sandbox Code Playgroud) 我有一个以这种方式定义的数组(提取数据集的第三列):
value=[]
value.append((p[3]))
x=np.array(value)
Run Code Online (Sandbox Code Playgroud)
如果我想获得一个包含数组x的Log10(不同函数)的新数组,该怎么办?我尝试过:
logx=np.array(log(x))
Run Code Online (Sandbox Code Playgroud)
但它给了我以下错误:
TypeError: 'numpy.ufunc' object is not subscriptable.
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我需要Python 2.7中的数据验证问题的帮助,它做我想要的不接受字符串,但它不接受整数,因为它应该做.
def GetKeyForCaesarCipher():
while True:
key =(raw_input('Enter the amount that shifts the plaintext alphabet to the ciphertext alphabet: '))
try:
i=int(key)
break
except ValueError:
print ('Error, please enter an integer')
return key
Run Code Online (Sandbox Code Playgroud) 我一直遇到这个python代码的问题.我刚刚开始编码,我无法弄清楚它为什么不起作用.我不能让循环停止重复.无论我输入什么,它都会启动add_item功能.有小费吗?
supply = { #Creates blank dictionary
}
print "Would you like to add anything to the list?"
def add_item(*args): #Adds a item to the supply dictionary
print "What would you like to add?"
first_item = raw_input()
print "How much does it cost?"
first_price = raw_input()
supply[first_item] = float(first_price)
response = raw_input()
while response == "yes" or "Yes" or "YES":
if response == "yes" or "Yes" or "YES": #Added this because it wasn't working, didn't help
add_item()
print "Alright, your …Run Code Online (Sandbox Code Playgroud) vowlist=['a','e','i','o','u']
def piglatin(s):
if len(s)==1:
if s[0] in vowlist:
return s[0]+'way'
else:
return s[0]+'ay'
elif s[0]==' '*len(s):
return ' '
elif len(s)>1:
if s[0] in vowlist or (s[0]=='y' and s[1] not in vowlist):
return s[0:]+'way'
else:
return new(s)
def new(s):
global str
if s[0] not in vowlist:
str=s[0]+new(s[1:])
else:
return s[len(str):]+str[0:]+'ay'
print piglatin('school')
print piglatin('yttribium')
print piglatin('yolo')
Run Code Online (Sandbox Code Playgroud)
这是我写的代码。它应该输出:
oolschay
yttribiumway
oloyay
Run Code Online (Sandbox Code Playgroud)
但它给出了错误object of type 'type' has no len()这是为什么?
请帮我完成这项功课:
makeA({0:1,2:1,4:2,6:1,9:1})
输出应该是这样的:
[1, 0, 1, 0, 2, 0, 1, 0, 0, 1]
Run Code Online (Sandbox Code Playgroud) 我必须将压缩列存储中的稀疏矩阵与列向量相乘(我必须在开放式cl中并行化它)。我在互联网上进行了搜索。花了很多天但找不到任何东西。(我被允许搜索互联网因为我必须将其转换为并行)。但我只能找到压缩行存储的代码。
spmv_csr_serial(const int num_rows ,
const int * ptr ,
const int * indices ,
const float * data ,
const float * x,
float * y)
{
for(int row = 0; i < num_rows; i++){
float dot = 0;
int row_start = ptr[row];
int row_end = ptr[row+1];
for (int jj = row_start; jj < row_end; jj++)
dot += data[jj] * x[indices[jj]];
y[row] += dot;
}
}
Run Code Online (Sandbox Code Playgroud)
压缩列存储没有行指针。那么如何将它与向量相乘呢?我只需要串行代码,然后我自己将其转换为并行代码。
这是我用于该项目的 OpenCL 内核
enter code here
__kernel void mykernel(__global const int* val,__global …Run Code Online (Sandbox Code Playgroud) import java.util.Scanner;
import java.lang.String;
public class SA3
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter student record : ");
String scores = scan.nextLine();
String[] StringOfMarks = scores.split(",");
double[] Marks = new double[StringOfMarks.length];
for(double i = 0; i < StringOfMarks.length; i++)
{
Marks[i] = StringOfMarks[i];
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有CommentRating一个持有外键的表DrinkId.我试图获得每个的平均评分DrinkId,并且我想要显示评分最高的前三名饮料.
commentRating drinkID
9 7
9 4
8 11
8 7
7 4
6 4
6 11
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的SQL,但我不知道如何更改它.
Select TOP(3)(AVG(commentRating)),DISTINCT(drinkID)
FROM Comment order by commentRating desc
Run Code Online (Sandbox Code Playgroud)
我如何平均评分,选择前三个评级的饮料,并在SQL中返回?
康托尔的可数无限和无数无限无限的集合
您可能知道并且您可能已经证明0到1之间的实数集是无穷无尽的.意味着我们无法映射不同自然数上的每个数字.
我得到了一种技术,通过该技术,我可以在不同的自然数上映射0到1之间的所有实数.技术很简单用1替换小数点并在该数字上映射原始数据使得10003上的地图0.0003和103上的0.03
通过使用这种技术,我们将能够在自然数上映射0到1之间的所有实数.所有这些自然数将从1开始,所以我们将有其他数字,其中没有数字将被映射为2或211或79所以这意味着一组自然数是格雷特然后实数在0和1之间.因此0到1之间的实数集是可数无限的.
什么是Ur意见?
我一直在接受ZeroDivisionError.我的代码如下.什么似乎是我的问题?
def number(x):
for i in range(x):
if x%i == 0:
print(i)
Run Code Online (Sandbox Code Playgroud) python ×6
c ×2
c++ ×1
countable ×1
dictionary ×1
function ×1
infinite ×1
java ×1
loops ×1
math ×1
numpy ×1
opencl ×1
python-3.x ×1
set ×1
set-theory ×1
sql ×1
sql-server ×1
typeerror ×1
validation ×1
while-loop ×1
zlib ×1