Thread: Alphanumeric array

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39

    Cool Alphanumeric array

    Hi all,
    I have an alphanumeric array "31A16XB 5B4A3D 3P2RX".I want the solution of this array in a way i am going to mention.
    The numbers are multiplied by 26 and the next alphabet's position(0-25) is added to it.
    for example,
    For 31A =31*26 +(position of A that is 0)=806
    and for 16X=16*26+(position of X that is 23)=439
    and for B=(only position of B that is 2)=1
    Continue in this way i need 806,439 and 1 etc. in an array as a final output.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    And your question is....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39
    Dear,
    My question is in the final line.I need another array which is obtained by the above process,
    thanxxxxxxxxxxxxx

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    So, what have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39
    Dear,
    i want the solution of this problem.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i want the solution of this problem.
    Please read the homework policy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Quote Originally Posted by rehan View Post
    Dear,
    i want the solution of this problem.
    I want a space ship. I'll give you the solution if you give me a space ship.
    Don't quote me on that... ...seriously

  8. #8
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    What the heck, rules are made to be broken
    Code:
    #include <iostream>
    #include <deque>
    #include <sstream>
    
    using namespace std;
    deque <char> OO;
    deque<int> OOO;
    typedef stringstream QQ;
    int l1,l,lO5;
    
    void main()// >;-)
    {
         for(int O=lO5;O<sizeof("31A16XB 5B4A3D 3P2RX")-1;++O)
         {
              QQ QQQ;
              if(isdigit("31A16XB 5B4A3D 3P2RX"[O]))OO.push_back("31A16XB 5B4A3D 3P2RX"[O]),l=1;
              else if("31A16XB 5B4A3D 3P2RX"[O]==' ')continue;
              else if (!l)l1=lO5+("31A16XB 5B4A3D 3P2RX"[O])-'A',l=1,OOO.push_back(l1),l1=lO5;
              else QQQ << string(OO.begin(),OO.end()),QQQ >>l1,OOO.push_back(l1*26+("31A16XB 5B4A3D 3P2RX"[O])-'A'),l=lO5,l1=lO5,OO.clear();
         }
         for(unsigned O=0;O<OOO.size();O++)cout << OOO[O]<<"\n";
    }
    Hope you get an A :-)
    Last edited by Darryl; 07-24-2007 at 09:39 AM.

  9. #9
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39
    Thanxxxxxxxx Darryl,
    this is a way,i am working on it.

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Darryl, didn't you miss a couple of oppurtunites for creative use of #define there?

    I love that code, it's so pretty.... And you seem to have satisfied Rehan too, which is good.

    ;-)

    --
    Mats

  11. #11
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by matsp View Post
    Darryl, didn't you miss a couple of oppurtunites for creative use of #define there?

    I love that code, it's so pretty.... And you seem to have satisfied Rehan too, which is good.

    ;-)

    --
    Mats
    Yea, I think I let my principals get in the way of my creativity, It's liked second nature for me not to use #defines that I didn't even think too. Plus this is the c++.

  12. #12
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Ah, almost all the "best" practices of C++ in one:
    - using directive;
    - globals;
    - l and O and 1 and 0 in variable names is always fun!!!
    - space-efficient spacing (makes the code concise and program faster too);
    - clever use of typedefs to make code even more effective;
    - magic values (much better than using constants, which would always make you look up what l0OO1l stands for);
    - nice use of comma-operator - wow, this code must be fast!

    Couple of things are missing though.
    #include <iostream.h>
    #defines - a must for fast code
    goto - for extra fast code.

    I'm sure the professor will be delighted!
    -
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  13. #13
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by anon View Post
    Ah, almost all the "best" practices of C++ in one:
    - using directive;
    - globals;
    - l and O and 1 and 0 in variable names is always fun!!!
    - space-efficient spacing (makes the code concise and program faster too);
    - clever use of typedefs to make code even more effective;
    - magic values (much better than using constants, which would always make you look up what l0OO1l stands for);
    - nice use of comma-operator - wow, this code must be fast!

    Couple of things are missing though.
    #include <iostream.h>
    #defines - a must for fast code
    goto - for extra fast code.

    I'm sure the professor will be delighted!
    -
    <iostream.h> wouldn't have compiled on VS2005
    goto, like #define are both excellent suggestions, it's just that I am programmed not to use them so didn't even consider it. Most obfuscated code is C based, which IMHO is much easier to obfuscate,considering it pretty much is anyway :-) Anyway, I'd like to think of mine as Obfuscated C++

    I wonder if he really will use the code, if he couldn't do the original problem, he won't understand this code and therefore won't be able to clean it up. Not saying it needs cleaning, except, of course, for that obviously evil void main()
    Last edited by Darryl; 07-26-2007 at 08:21 AM.

  14. #14
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39
    Thanxxxxx guys,
    you really gave me an efficient code,i tried it a little bit differently and it worked the way i want it in my program.

  15. #15
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I hope you realized this code is an evil joke. It may do what you want but it is not clearly an acceptable way to write a program.

    There are certain steps that you can do almost automatically to "deobfuscate" the code somewhat. If you managed to do that you must know something about C++ programming and have some insight into what's going on here, therefore presenting the code wouldn't mean that much cheating.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. from 2D array to 1D array
    By cfdprogrammer in forum C Programming
    Replies: 17
    Last Post: 03-24-2009, 10:33 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM