|
for example there is a four bits integer 1122, if someone guess and inout 1234, because 1 and 2 are in 1122, and the position is same, the computer will tell you that you are right with two numbers and they are 1 and 2;
as follows is my program, I thinnk they are too complex , could some tell me a simple algorithm, thinks in advantage
#include <stdio.h><br />
#include <stdlib.h><br />
<br />
int main()<br />
{<br />
int data1 = 1234;<br />
int data2;<br />
int gewei1, shiwei1, baiwei1, qianwei1;<br />
int gewei2, shiwei2, baiwei2, qianwei2;<br />
int count = 0;<br />
<br />
gewei1 = data1%10;<br />
shiwei1 = (data1%100)/10;<br />
baiwei1 = (data1%1000)/100;<br />
qianwei1 = data1 /1000;<br />
<br />
int arr1[4] = {qianwei1, baiwei1, shiwei1, gewei1};<br />
<br />
printf("Please Enter a interger:");<br />
scanf("%d", &data2);<br />
<br />
gewei2 = data2%10;<br />
shiwei2 = (data2%100)/10;<br />
baiwei2 = (data2%1000)/100;<br />
qianwei2 = data2 /1000;<br />
int arr2[4] = {qianwei2, baiwei2, shiwei2, gewei2};<br />
<br />
for (int i=0; i<4; i++)<br />
{<br />
if(arr1[i] == arr2[i])<br />
{<br />
printf("%d ", arr1[i]);<br />
count++;<br />
}<br />
else<br />
continue;<br />
}<br />
printf("the same number is %d ", count);<br />
return 0;<br />
}
|
|
|
|
|
wbgxx wrote: for example there is a four bits integer 1122, if someone guess and inout 1234, because 1 and 2 are in 1122, and the position is same
The position is NOT the same, actually.
wbgxx wrote: I thinnk they are too complex , could some tell me a simple algorithm
You may make it more concise, anyway, since the current logic looks correct I doubt it would be simpler.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Why not just use straight character comparisons rather than this complex mathematics:
foreach character c in usersguess
begin
if c in secretnumber
then
save c in savearray
end
It's time for a new signature.
|
|
|
|
|
could you give me detail??Thanks
|
|
|
|
|
wbgxx wrote: could you give me detail?
It's in my previous message; a simple loop comparing each character in one string with the characters of another string. If you are not able to convert that to C++ then I suggest you spend a little more time with your study guides.
It's time for a new signature.
|
|
|
|
|
I use IME to control i/o in Japanese and Chinese. While using an edit control for input, everything works fine. When I use the same edit control for editing an existing text string, the original string is shown as bytes instead of the Japanese Hiragana characters. More characters can be entered, and the result is correct, but the appearance is ugly. Should I be using ImmSetCompositionString() or something else, and if so, does anyone know how?
|
|
|
|
|
I need to find c++ code to solve M simultanous linear equations with N variables - N
|
|
|
|
|
Don't we all!
anyway, have a look at the free LAPACK packages.
Watched code never compiles.
|
|
|
|
|
|
Hi All,
I downloaded a project "Virtual grid"(VS6) from this site and when i used VS2008 to work with it, I am getting the following error when i try to debug.
"This application has failed to start because mfc90d.dll was not found. Re-installing the application may fix the problem."
The release version works fine without this issue.
i can see the mfc90d.dll in my local machine at C:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugMFC_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_2a62a75b
i added this path to tools->options->vc++ directories->library files
But did not help.
If anyone run thru similar issue, please help.
Kasi
|
|
|
|
|
I replied earlier, but the hamsters went snafued ...
Best practice is to post questions about articles on the articles discussion section (at the bottom of the article).
Watched code never compiles.
|
|
|
|
|
|
After I add a progess bar on the dialogue box, I added code:
m_progress1.SetRange(0,100);
m_progress1.SetStep(1);
in OnInitDialog(), and m_progress1.SetPos(mmtt);
in the Next(). WHen I tried to run the program, the blue blocks representing the progress can not be seen in the progress bar. In other words, the progress bar is only an empty rectangular grew box when I run the program until finish.
Please help how to make it work.
Thanks
|
|
|
|
|
mrby123 wrote: ...and m_progress1.SetPos(mmtt);
in the Next().
When does Next() get called? What is the value of mmtt ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
After click the next button in the dialogue box.
Thanks
|
|
|
|
|
Are you aware that if you have a lenghty operation in the main thread, UI messages won't be processed until the task is finished ? This means that the UI won't be redrawn and you won't be able to see any progress in the bar until the end of the task (in which case, all messages are processed at once and the progress is full).
A better approach would be to run your lenghty task in a separate thread. I really recommand reading this excellent article[^] about threading.
|
|
|
|
|
I need a SDI with MFC in windows sever 2003,vs2005,the CPU is Core 2 Q8200.
I create a SDI with MFC, it can run.
for I need large memory , then I set the configuration x64.
compling error, "MD/switch" off.I set on this switch.
now fatal linking error 1561: entry point need define.
but "theApp" object indeed exist.
(I have a not SDI code in VC,it can run when I set the configuration x64.)
Why?
Please teach me.
Thanks you.
Lee Wen.
modified on Tuesday, July 6, 2010 2:39 PM
|
|
|
|
|
What specific linker error?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Thank you!
fatal error Link 1561:need define entry point.
|
|
|
|
|
hztj2005 wrote: fatal error Link 1561:need define entry point.
Did you see here?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
fatal error LNK1561: entry point must be defined”
I have build successly,by set the linker/subsystem:windows
Thanks very much.
|
|
|
|
|
Hi,
I'm trying to enable my ARM development board to communicate with a PC. I can establish a connection and send data from the PC to the micro without any issues. When I try to send data from the micro to the PC, however, my socket doesn't respond to the data. A network analyzer shows that the packet was sent and formated properly. I have tried both TCP and UDP with the same results. Has anyone come across this before?
Thanks.
|
|
|
|
|
masnu wrote: When I try to send data from the micro to the PC, however, my socket doesn't respond to the data.
Can you elaborate what you mean by that? Can you connect from the microcontroller to the PC, can you receive data but not send, etc...
|
|
|
|
|
Yes I can connect to the micro and send data from the PC to the micro but not the other way around. My socket is created as follows:
Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
And then I wait for data:
fd_set sckt;
timeval timeout;
timeout.tv_sec = 2;
timeout.tv_usec = 0;
FD_ZERO( &sckt );
FD_SET( Socket, &sckt );
int nRet = select( 0, &sckt, 0, 0, &timeout );
select always returns 0 indicating a timeout no matter how much data I send from the micro.
|
|
|
|
|
If the TCP handshake is successful, you are actually sending packages from the microcontroller to the PC. This lets me wonder if the error you see is on application level, perhaps your socket code is not working properly, could be both client or server side. In the code snippet you provided there is no connect or bind/listen call, so I would not expect the socket to change status.
1) Have you tried connecting to your PC socket application from another PC (or via loopback)?
2) What error code do you get when connecting from microcontroller to PC? Timeout or something else?
3) Have you checked with Wireshark that TCP handshake is fine and packages are properly ACKed?
4) Which TCP stack are you using on the micocontroller (ARM SDK)? Could the problem not be Winsock at all?
|
|
|
|