HW First system problem, second Test, HW test system sucks _ interview related

Source: Internet
Author: User

Attention matters
1. Each question can only be submitted 5 times;
2. The program obtains input from standard input stdin (' Standard input ') and outputs output to standard output stdout (' Standard output ').
3. Input and output can not contain any hint information;
4. The compiler core of the test platform is VS2005 and JDK1.7. When using the Java answer, the class name must be "Main", do not use the Package keyword declaration, and use the data types and functions supported by VS2005 when using C + + answer questions;
5. No file operation is allowed in the code;
6. Submit the answer when submitting all the code, including the main function and all child functions;
7. It is recommended that you submit the test system after the local compilation is completed;
8. After the answer is submitted, click on the status can see the results of the sentence and the corresponding prompts;
9. Information Registration link can not be skipped, otherwise can not export results.


The first problem is to find the characters with the most occurrences of the most characters in the input string


Results:

#include <iostream>
#include <string>
using namespace std;

Char mostpresnet (char *test)
{
    unsigned int app[26];
    for (int j=0;j<26;j++)
	{
		app[j]=0
	}
    while (*test!= ' ")
    {   
		++app[(unsigned char) (*test-' a ')];
		test++;
	}
    char re=0;
    for (int i=0;i<26;++i)
       if (App[i]>app[re]) re= (char) i;
    Return re+ ' a ';
}

int main () {
 string str;
 char result;
cout<< "Plase Enter the char:";
 Char *input=new char[128];
 cin>>str;
 cin>>input;
/* if (str.size () >128) {return
	0;
 }

 int len=str.size ();
 for (int j=0;j<len;j++)
 {
  if (str[j]>= ' a ' &&str[j]<= ' z ')
  {
    input[j]=str[j];
  }
  else{return
   	0;
  }
 * *
 
 result=mostpresnet (input);
 cout<<result;
 return 0;
}
The second question is bracket matching.

#include <iostream> #include <stdio.h> #include <string.h> using namespace std;
    #define STACKSIZE 128 struct Stack {char strstack[128];
int top;

};

void Initstack (Stack &s) {s.top=-1}
    Char Push (Stack &s,char a) {if (s.top==128-1) {return 0;
    } s.top++;
    S.strstack[s.top]=a;
return A;
    } char Pop (Stack &s) {if (s.top==-1) {return 0;
    } Char A=s.strstack[s.top];
    s.top--;
return A;
    ' int Empty (stack &s,int re) {if (s.top==-1) {return 1;
    else {return 0;
    } int Check (char *str) {stack S;
    Initstack (s);
    int Strn=strlen (str);
        for (int i=0;i<strn;i++) {char a=str[i];
            Switch (a) {case ' (': Push (s,a);
        Break
            Case '] ': if (Pop (s)!= ' (') {return 0;
        } break; } int re=0;
    Re=empty (S,re);
return re;
 int main () {char *str=new char[128];
    cout<< "Please enter a string of less than 128 length:" <<endl;
    cin>>str;
    int Re=check (str);
	cout<<re<<endl;
return 0; }

Originally in their own system to test all good, but on the HW always say there are errors, and finally feel that the output of the problem, must have cout<<result<<endl;

Finally, I think the HW test system needs to be improved ~


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.