Roshan
Can anyone please help me out in this question. I have made the code it works fine as per me, but the app doesn't give me all test cases correct.
Roshan
Can anyone please help me out in this question. I have made the code it works fine as per me, but the app doesn't give me all test cases correct.
Que-> Given the sizes and left or right shoe, determine the pairs that can be formed with sizes being equal and left and right shoe. Pasting the code...
Roshan
https://hastebin.com/zevutofede.cpp
Roshan
Anyone?
Prince Of Persia
No
Also pointers?
Prince Of Persia
What about a MyChar pointer to char
Prince Of Persia
•Msu•
Pele Persian
Anonymous
Yes
Nice too meet
Prince Of Persia
Nice too meet
Nice to meet you too
Prince Of Persia
Are you Persian too?
Anonymous
Anonymous
Prince Of Persia
What about a MyChar pointer to char
@unterumarmung I guess pointers can do
Roshan
Did Somebody say anything?
Roshan
Nope 🙂
That's you 🤣 Having any solution?
Anonymous
That's you 🤣 Having any solution?
Just specify exactly what you're stuck with currently , I'm sure someone will help you out.
Anonymous
Mentioned it in earlier messages...
Can you give me an i/p and o/p?
Roshan
Can you give me an i/p and o/p?
Do you mean input and output?
Anonymous
Yes
Roshan
Can you give me an i/p and o/p?
Can I DM the question
Anonymous
ok
Roshan
Hey, can anyone code a 22 lines python code to c++ ?
Roshan
Hey, can anyone code a 22 lines python code to c++ ?
https://www.includehelp.com/python/shoes-matching-competitive-coding-questions.aspx This code
Ludovic 'Archivist'
Hey, can anyone code a 22 lines python code to c++ ?
probably doable in less than 22 lines in C++
Ludovic 'Archivist'
Yep, doable in 19 lines in C++
Ludovic 'Archivist'
https://www.includehelp.com/python/shoes-matching-competitive-coding-questions.aspx This code
https://gist.github.com/Zenohate/2c8ddea5cdeb7a4ae9dc7cc4dba516c7
Ludovic 'Archivist'
It is still probably possible to shave more lines off
Roshan
https://gist.github.com/Zenohate/2c8ddea5cdeb7a4ae9dc7cc4dba516c7
Sorry, I don't know STL, please do it in traditional way....
Manav
Sorry, I don't know STL, please do it in traditional way....
Learn STL then, it is there for people to use it, unless one has incredibly specific hardware requirements, etc.
Roshan
STL is the traditional way
Ok then the other way of dealing with it 😅
Manav
So operator [] need return a Char reference
If you have wrapped char with your own Char class like this: class Char { char base; public: Char(char c) { base = c } } Then you could just return char& inside the operator [] in your string class. The default constructors created for the Char class would take care of creating a Char object from char for you If you want more control you can override char() operator https://del.dog/efeckenayl.cpp
Anonymous
Ok then the other way of dealing with it 😅
get this book, C++ Primer by Stanley Lippman et el. (5th edition for C++11), it's a great book for C++
Anonymous
You will need STL if you want to push higher rank/ratings on competive programming platforms like codeforces, atcoder, topcoder, etc.
Manav
Interesting
The default constructor, copy constructor, etc are created for you if you don't define one of them. :) Though I wouldn't recommend wrapping base types like char, int etc unless you have a very good reason
Manav
cannot bind non-const lvalue reference of type ‘Char&’ to an rvalue of type ‘Char’
Like I said you will have to create char() operator if you want more control
Prince Of Persia
class Char : public Any{ private: char holder = '\0'; public: Char(); Char(char&); ~Char(); Char& operator=(char&); operator char(); Int toInt() const; Int toIntC() const; String toString() const; };
Manav
how it will work? is it fast?
Idk, it will be slower I think. Will have to test this. Why are you even wrapping base types if you want something fast.
Prince Of Persia
but anotherthing
Manav
OK I want to delete Char class for 1-this problem 2-utf-8 problem
utf8 aaah, I see. Can't help you there haha. I don't have much experience with handing encoded strings
Prince Of Persia
how to know length of a utf-8 char in std::string??
Manav
how to know length of a utf-8 char in std::string??
Utf8 is 8 bits per character so 8 bits I guess
Prince Of Persia
it have range 1-4 Byte
Manav
it have range 1-4 Byte
Could just do sizeof() couldn't you?
Prince Of Persia
احمد each char have 2Byte
Prince Of Persia
Ahmed each char have 1 Byte
Manav
Ahmed each char have 1 Byte
That's not always true. Sizes are infrastructure dependent afaik
Manav
For a 64 bit machine, lemme see
Prince Of Persia
Ludovic 'Archivist'
That's not always true. Sizes are infrastructure dependent afaik
char is guaranteed to be 1 bytes, but it also defines the byte in C and C++. It is not, however, guaranteed to be 8 bits
Prince Of Persia
int size(char* s){ int len = 0; while (*s){ len += (*s++ & 0xc0) != 0x80; } return len; }
Prince Of Persia
this code say how many utf-8 are in char*
Ludovic 'Archivist'
Isn't that only for C?
No, but in C++ a byte must be able to at least represent a utf8 character of one code unit
Prince Of Persia
Why use pointer for char? That's wasteful afaik
char* and std::string are same in utf-8
Manav
char* and std::string are same in utf-8
Nvm 😑, for a moment I thought you were manipulating a char with a pointer, not C string
Ludovic 'Archivist'
but how?
It counts every code unit that marks the start of a utf8 character
Prince Of Persia
Manav