casting

What's wrong with long? Why is subtracting 1 automatically?

大城市里の小女人 提交于 2021-02-17 06:57:10
问题 #include <iostream> #include <math.h> #include <algorithm> using namespace std; int main() { int t, c1, c2, res; string str1, str2; cin >> t; for (int i = 0; i < t; i++) { c1 = c2 = res = 0; cin >> str1 >> str2; c1 = count(str1.begin(), str1.end(), '1'); c2 = count(str2.begin(), str2.end(), '1'); cout << (long)(((pow(10, c1) - 1) / 9) * ((pow(10, c2) - 1) / 9)) << '\n'; } } For input: 1 11111 11111 Output is: 123454321 but, here is the problem, For input: 1 10101 10100 Output is: 1220 Also,

com.google.gson.JsonObject cannot be cast to com.google.gson.JsonArray

邮差的信 提交于 2021-02-16 18:00:41
问题 I have some trouble with parsing a JSON response. The response data: { "deal": { "categorie": { "description": "Offres Shopping", "idcategorie": "1", "nom": "Shopping" }, "conditions": "2 personne au plus", "dateAjout": "2013-01-07T00:00:00+01:00", "dateExp": "2013-01-31T00:00:00+01:00", "description": "nuit dans un hotel 5 etoile", "heurexp": "12", "iddeal": "1", "minutesexp": "30", "prestataire": { "adresse": "Qu zohour 44", "codePostale": "12600", "description": "Hotel 5 etoiles",

com.google.gson.JsonObject cannot be cast to com.google.gson.JsonArray

 ̄綄美尐妖づ 提交于 2021-02-16 18:00:08
问题 I have some trouble with parsing a JSON response. The response data: { "deal": { "categorie": { "description": "Offres Shopping", "idcategorie": "1", "nom": "Shopping" }, "conditions": "2 personne au plus", "dateAjout": "2013-01-07T00:00:00+01:00", "dateExp": "2013-01-31T00:00:00+01:00", "description": "nuit dans un hotel 5 etoile", "heurexp": "12", "iddeal": "1", "minutesexp": "30", "prestataire": { "adresse": "Qu zohour 44", "codePostale": "12600", "description": "Hotel 5 etoiles",

PySpark returns an exception when I try to cast string columns as numeric

試著忘記壹切 提交于 2021-02-11 14:00:38
问题 I'm trying to cast string columns to numeric, but I am getting an exception in PySpark. I provide below the code and the error message. Is it possible to import the specific columns from the csv file as numeric? (the default is to be imported as strings). What are my alternative? My code and the error messages follow below: import pandas as pd import seaborn as sns import findspark findspark.init() import pyspark from pyspark.sql import SparkSession # Loads data. Be careful of indentations

SQL Server : conversion error numeric to varchar case

若如初见. 提交于 2021-02-11 08:02:53
问题 I have this query: CASE ClaimsFees.TBA WHEN 0 THEN CAST(IndemnityReserve AS NUMERIC(9,2)) ELSE 'TBA' END AS 'Reserve Indemnity' but I always get this error: Error converting data type varchar to numeric I have tried to convert TBA as numeric but I can't do this, I also can't convert all the results to varchar because when I transfer to Excel file the number 1.325,27 becomes 132.527,00 with the ##,##0.00 format. Is there a method in SQL Server that I can use to solve this? 回答1: The column can

basic_regex throws bad_cast with char32_t

北城余情 提交于 2021-02-11 06:51:07
问题 Why does the following code generate std::bad_cast exception? #include <iostream> #include <regex> #include <string> int main() { std::basic_string<char32_t> reg = U"^\\w"; try { std::basic_regex<char32_t> tagRegex(reg); } catch(std::exception &e) { std::cout << e.what() << std::endl; } return 0; } This sample on Ideone for convenience: https://ideone.com/Saea88 Using char or wchar instead of char32_t runs without throwing though (proof: https://ideone.com/OBlXed). 回答1: You can find here:

Why can't I cast a Box with an extended trait to a Box with the base trait? [duplicate]

北战南征 提交于 2021-02-10 17:08:14
问题 This question already has answers here : Why doesn't Rust support trait object upcasting? (3 answers) Closed 2 years ago . Given the code trait Base { } trait Derived : Base { } struct Foo { } impl Base for Foo { } impl Derived for Foo { } fn main() { let b : Box<Derived> = Box::new( Foo { } ); let a : Box<Base> = b; } When I compile as I'm sure you know I get the following error message: error[E0308]: mismatched types --> src/main.rs:14:25 | 14 | let a : Box<Base> = b; | ^ expected trait

Why can't I cast a Box with an extended trait to a Box with the base trait? [duplicate]

偶尔善良 提交于 2021-02-10 17:05:19
问题 This question already has answers here : Why doesn't Rust support trait object upcasting? (3 answers) Closed 2 years ago . Given the code trait Base { } trait Derived : Base { } struct Foo { } impl Base for Foo { } impl Derived for Foo { } fn main() { let b : Box<Derived> = Box::new( Foo { } ); let a : Box<Base> = b; } When I compile as I'm sure you know I get the following error message: error[E0308]: mismatched types --> src/main.rs:14:25 | 14 | let a : Box<Base> = b; | ^ expected trait

Why can't I cast a Box with an extended trait to a Box with the base trait? [duplicate]

喜你入骨 提交于 2021-02-10 17:04:35
问题 This question already has answers here : Why doesn't Rust support trait object upcasting? (3 answers) Closed 2 years ago . Given the code trait Base { } trait Derived : Base { } struct Foo { } impl Base for Foo { } impl Derived for Foo { } fn main() { let b : Box<Derived> = Box::new( Foo { } ); let a : Box<Base> = b; } When I compile as I'm sure you know I get the following error message: error[E0308]: mismatched types --> src/main.rs:14:25 | 14 | let a : Box<Base> = b; | ^ expected trait

Casting const void* to const int*

限于喜欢 提交于 2021-02-10 15:54:09
问题 I haven't used void* and const_correctness before so I am not understanding what I am doing wrong in the below code. All I want is to cast a void* returned by a member function of a const object to int*. Please suggest better approaches. Thank you. I get the following error passing 'const MyClass' as 'this' argument of 'void* MyClass::getArr()' discards qualifiers So here's the actual program that I had problem with class MyClassImpl{ CvMat* arr; public: MyClassImpl(){arr = new CvMat[10];}