Computing desk | ||
---|---|---|
< February 15 | << Jan | February | Mar >> | February 17 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
I wrote the following code in order to conform to the requirement. Although the code appears to have met the requirement, I feel it inefficient because I don't expect to write a lot of case
when the array size grows to 100 or more, i.e. storage[100]
. So I would like to ask if any Wikipedian knows about the more efficient way to approach such requirement? Thanks a lot! :D Stringent Checker (talk) 14:49, 16 February 2021 (UTC)
/*
Write a program that searches an array of ten integers for duplicate values.
Have the program display each duplicate found.
*/
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int input;
int storage[10];
cout << "Insert 10 integers and the program will check if there are duplicate integers in the array. \n";
for (int i = 0; i < 10; i++)
{
switch (i) {
case 0:
cout << "Now, insert the first number.\n";
cin >> input;
storage[0] = input;
break;
case 1:
cout << "Now, insert the No." << i + 1 << " number.\n" ;
cin >> input;
storage[1] = input;
break;
case 2:
cout << "Now insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 3:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 4:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 5:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 6:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 7:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 8:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
case 9:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
break;
}
}
for (int i = 0; i < 10; i++)
{
for (int j = 10 - 1; j >= 0; j--) {
if (j == i) continue;
if (storage[i] == storage[j] && i < j) cout << "Duplicate found: " << storage[i] << "\n";
}
}
cout << "The 10 numbers you inserted: ";
for (int i = 0; i < 10; i++)
{
cout << storage[i];
}
return 0;
}
switch
statement with a simple if
statement that asks if (i > 0)
do your current case 2 ( ask for number i+1
and store it as storage[i]
) else
do your current case 0 — GhostInTheMachine talk to me 16:53, 16 February 2021 (UTC)switch
and maybe have case 1:
say cout << "Now, insert the second number.\n" ;
, then replace all cases from 2 to the end with a single default
— GhostInTheMachine talk to me 16:53, 16 February 2021 (UTC)
j
run up instead of down, starting from j = i+1
, you can omit the two tests j == i
(always false) and i < j
(always true); moreover, you more than halve the number of comparisons storage[i] == storage[j]
. Note that if all 10 numbers are the same, the code will produce 45 lines of found duplicates. --Lambiam 18:27, 16 February 2021 (UTC)
The code now looks like this, seems to be more clear and concise. As to My general advice is not to code more than explicitly required – except perhaps for such things as input validation or catching exceptions.
I have taken notes about this and will mind this insightful point going forwards. Any further advice is greatly appreciated! Thanks for the community's generosity in upbringing the next generation. I will keep this Wikipedian culture! Stringent Checker (talk) 17:37, 18 February 2021 (UTC)
/*
Write a program that searches an array of ten integers for duplicate values.
Have the program display each duplicate found.
*/
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int input;
int storage[20];
cout << "Insert 20 integers and the program will check if there are duplicate integers in the array. \n";
for (int i = 0; i < 20; i++)
{
switch (i) {
case 0:
cout << "Now, insert the first number.\n";
cin >> input;
storage[0] = input;
break;
case 1:
cout << "Now, insert the No." << i + 1 << " number.\n";
cin >> input;
storage[1] = input;
break;
default:
cout << "Now insert the No." << i + 1 << " number.\n";
cin >> input;
storage[i] = input;
}
}
cout << "Duplicate found: ";
for (int i = 0; i < 20; i++)
{
for (int j = i + 1; j < 20; j++) {
if (storage[i] == storage[j] ) cout << storage[i];
}
}
cout << "\n" << "The 20 numbers you inserted: ";
for (int i = 0; i < 20; i++)
{
cout << storage[i];
}
return 0;
}
There are a lot of data recovery services for things like damaged hard drives or tape or flash storage.
But in my case, I got a software fault in my RocksDB database which corrupted data or it’s masked crc32 checsum on a single key (less than 1 Mb) thereby preventing the built in Snappy compression (managed by Rocksdb libraries) from decompressing.
While the data is public and available through many third party services for free, it’s access as a database is not, and rebulding it using OpenEthereum (full archival node) is a year long operation (using the current cpu providing the best per thread performance because otherwise it can be way longer) because of single thread performance constraints (OpenEthereum suffer from synchronisation issues which limits the overall number of threads which can work at the same time and the required work around increasing io worker threads parallelism was never attempted so far). This also mean that I’m not interested in extracting the damaged data, but instead really need the database to no longer crash OpenEthereum.
Of course, from the around 2000 OpenEtherem full archival node in the world, I did not find a company willing to share a backup for fixing the broken part of my database or I didn’t received an answer.
This also means that it should be possible to delete all the blocs which where added at the end after the broken block (since data are stored in block based sst) along their matching data inside the 6 other columns. This can be done using the DeleteRange
function provided by RocksDB, but requires a deep understanding of the binary format used for key numbers. So a data recovery service with knowlwedgde about database repair is enough and there’s no need of Rocksdb specification though it might be a safer to replace the damaged key manually as attempting to rebuild the file through OpenEthereum might results in a 64Mb sst file not containing the same number of blocks as the original one. 2A01:CB05:8FEA:C600:D2E9:BABF:3376:10BD (talk) 19:14, 16 February 2021 (UTC)
I know it might be off topic to ask that here but I’ve really no idea about where to ask for a recovery company which might help me in that kind of case.
full Ethereum archival node
. While they are several type of software for running such kind of nodes, in my case, I need to check the result of transactions on past states in the mempool before they are mined in order to know if frontrunning a specific trade worth it. A feature called Parity trace, now part of OpenEthereum. 2A01:CB05:8FEA:C600:2198:8EE0:850E:2251 (talk) 11:37, 19 February 2021 (UTC)The corrupt sst file is here. 2A01:CB05:8FEA:C600:D5DB:E26D:D19B:C6C3 (talk) 15:19, 21 February 2021 (UTC)
I have a Hotmail account, but decided to create an Outlook one. However, whenever I try to log into Outlook, it automatically opens my Hotmail account. How can I access my new email account? Clarityfiend (talk) 20:25, 16 February 2021 (UTC)