"Souvenir stick" Android Development--Calculator

Source: Internet
Author: User

Process

Under the influence of e-commerce genius && code goddess Xufei, I was exposed to some development on the Android client, and for the first time an app was created on the Android platform, so it was really exciting, so I had to write a souvenir record.

I was going to fix the calculator all night, but when I saw the hype, it was a broken egg! Finally ate the barbecue .... Flying chess .... Gobang.... Also abused!!. T T

The next day and looked at the Chenyong code, feel can write, theoretically can make, but did not install the compiler ..... So take a night to install ... Finally ran up .... But do not know how to import the project ..... So only a file that can write code is opened. Not even grammar error, let alone can run up ..... Finally failed .....

The third day, on the roommate Zhangyizhong's computer, he wrote grammar, I write algorithms. Finally a semi-finished (and a lot of bugs) in front of my birth, to tell the truth is still very excited, I write something incredibly able to run on the phone!!! What an incredible thing!!!

From the computer console black box to the mobile app interface. A historic change .....

Technology

Some of the techniques of this calculator, the core is to convert infix expression to a suffix expression, this time need to use a most basic data structure-stack.

The specific operation principle can refer to this blog http://www.nowamagic.net/librarys/veda/detail/2307

However, for this problem, as early as the last semester has been resolved, but it was purely to accepted HDU 1237 http://acm.hdu.edu.cn/showproblem.php?pid=1237 Not to make a really useful calculator app. The development of the time, directly to the writing of the very lame code pulled down.

Android development seems to be using Java, have to say that this is a good language, integration of a lot of useful features, need to just call on the line, not like C + +, you have to play the pure hand.

The core code of the calculator is as follows: (at that time, even the stack is manually simulated, subtraction or the number indicated, the code is ugly.) )

#include <stdio.h>#include<string.h>//+ 999991//-999992//* 999993///999994intstack1[ +];Doublestack2[ +];inta[ +], b[ +];intMain () {inti; Chars[ +];  while(gets (s)) {if(strlen (s) = =1&& s[0] =='0') Break; inty =strlen (s); S[y]=' '; S[y +1] =' /'; intTOP1 =-1, TOP2 =-1, q =1, sum =0;  for(i =0; I<strlen (s); i++)        {            if(S[i] = =' '&& (S[i-1]<'0'|| S[i-1]>'9'))Continue; Else if(S[i] = =' ') A[q] = sum, sum =0, q++; Else if(S[i] = ='+') A[q] =999991, q++; Else if(S[i] = ='-') A[q] =999992, q++; Else if(S[i] = ='*') A[q] =999993, q++; Else if(S[i] = ='/') A[q] =999994, q++; Else if(S[i] >='0'&&s[i] <='9') sum =Ten* sum + (S[i]-'0'); }        //1 to Q-1; //for (i=1;i<q;i++) printf ("%d\n", A[i]);        intQQ =-1;  for(i =1; i<q; i++)        {            if(a[i]<999991) qq++, b[qq] =A[i]; Else if(A[i] >=999991)            {                if(Top1 = =-1)//stack is empty{TOP1++; STACK1[TOP1]=A[i]; }                Else                {                    if(A[i] = =999991|| A[i] = =999992)                    {                         while(1) {QQ++; B[QQ]=STACK1[TOP1]; Top1--; if(Top1 = =-1) Break; } TOP1++; STACK1[TOP1]=A[i]; }                    Else if(A[i] = =999993|| A[i] = =999994)                    {                         while(1)                        {                            if(STACK1[TOP1] = =999991|| STACK1[TOP1] = =999992|| Top1 = =-1) Break; QQ++; B[QQ]=STACK1[TOP1]; Top1--; } TOP1++; STACK1[TOP1]=A[i]; }                }            }        }         for(i = top1; I >=0; i--) qq++, b[qq] =Stack1[i];  for(i =0; I <= QQ; i++)        {            if(Top2 = =-1) {Top2++; STACK2[TOP2]=B[i]; }            Else if(b[i]<999991) top2++, stack2[top2] =B[i]; Else if(B[i] = =999991) Top2--, STACK2[TOP2] = Stack2[top2] + stack2[top2 +1]; Else if(B[i] = =999992) Top2--, STACK2[TOP2] = stack2[top2]-STACK2[TOP2 +1]; Else if(B[i] = =999993) Top2--, STACK2[TOP2] = stack2[top2] * STACK2[TOP2 +1]; Else if(B[i] = =999994) Top2--, STACK2[TOP2] =1.0*STACK2[TOP2]/Stack2[top2 +1]; } printf ("%.2lf\n", stack2[0]); }    return 0;}

Feeling

University for a year, in many books have seen this sentence: program = algorithm + data structure. Let me expand it, software = program + development tools, ie Software = algorithm + data structure + development tools. As with this calculator, the Black-box interface from the console has been developed into a software that allows people to use it, which is an important turning point. The program Design Competition examination Content 100% comes from the algorithm + data structure, to the development tool investigation equals zero! And for software outsourcing, service outsourcing those competitions, perhaps more focus on development tools, because to make a beautiful appearance to get a good reward. I have chosen a software engineering major and have a lot of potential for project development in the future (but it seems to be more interested in algorithmic research and innovation), so there is a little touch on development in addition to the competition. As Lvhao seniors say, they need T-shaped talent, if only to participate in the competition in the university, the vertical is really long, but the lack of that cross, not what they need.

Freshman so ended, participated in a few games, follow God Wang God and Wutianqi seniors participated in the province race, got AU, but my level is far less than they, from the Blue Bridge Cup national race they two are the country, I is second-class can see the gap. I remember last year when I did not know what is the C language, followed by Chenyanhong mentor and God Wang, the pace of the great God, 1.1 points from 0 accumulated to the present, the next semester to learn the data structure, I and Xiangrunye seems to have basically eaten, graph theory of the book gnawing to the network flow, Recently, we have been exposed to some dynamic programming and number theory, and there are many things to learn. There are some small partners who are weaker than us, and often worship why they can solve some of the problems they can't solve, just as I admire God Wang of our school, Zstu's Wuyiqi, Shu kuangbin them. Now, I think that's just a matter of time, because I almost put all the time into the competition, coding ability and program design ability is naturally slightly higher than others, time is long, practice makes perfect, of course, this should be based on good thinking, hard to learn. And the time we touch these things is far less than those of the great gods, so it's hard to overtake them.

You have to work very hard to look effortless.

"Souvenir stick" Android Development--Calculator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.