Huazhong University of Science and Technology _2008___ postgraduate Computer _ Second interview machine

Source: Internet
Author: User

1. Octal

Topic Description Narration:

Enter an integer to convert it to an octal output.

Input:

The input contains an integer N (0<=n<=100000).

Output:

There may be multiple sets of test data for each group of data.
The octal representation of the output n.

Example input:
789
Example output:
71011

Summary: Modulo 8 is to take the lower 3 bits. Then move the three-bit right, not the required rollover. Placed in the array, from the back to the forward output.

#include <iostream>using namespace Std;int main () {int n,i,j;int num[10000];while (cin>>n) {i=0;while (n) { num[i++] = N%8;n = n>>3;} for (j = i-1;j>0;j--) {cout<<num[j];} Cout<<num[0]<<endl;} return 0;}


2, longest & shortest text

Topic Description Narration:

Enter multiple lines of string. Please output the shortest and longest strings according to the order of the original text, assuming that the shortest and longest strings are more than one, all output.

Input:

The input contains multiple lines of string. The length of the string Len, (1<=len<=1000).

Output:

Outputs the shortest and longest strings in the order of the original text, assuming that the shortest and longest strings are more than one, all output.

Example input:
Helloshesorryhe
Example output:
Hehellosorry

Summary: This is what you think out of, some.

。。

。。。

#include <stdio.h> #include <string.h>int main () {int i=0;int h=0;int max[200];int k=0;int min[200];int len; Char Str[1000][1001];while (scanf ("%s", Str[i])! = EOF) {Len=strlen (Str[i]), if (k==0) {min[199] = len;min[k++] = i;i++; Continue;} if (Min[199]==len) {min[k++] = i;} if (min[199] > Len) {k=0;min[k++] = i;min[199] = len;} if (min[199] < Len) {if (h==0) {max[199] = len;max[h++] = i;i++;continue;} if (max[199] = = len) {max[h++] =i;} if (max[199] < Len) {h=0;max[h++] =i;max[199] = len;}} i++;} for (i=0;i<k;i++) {printf ("%s\n", Str[min[i]]);} for (i=0;i<k;i++) {printf ("%s\n", Str[max[i]]);} return 0;}


Summary: This is the reference, the structure is not required, the feeling is still some problems: assume that the input is the same string. Will output two times, will not be the subject of such requirements. The above code I also single-step debugging, did not find the error, is no accepted.

#include <stdio.h> #include <string.h> typedef struct{CHAR str[1001]; int Len;} charstring;        int main () {charstring arr[1000];        int cnt = 0;         int i,max,min;                while (scanf ("%s", arr[cnt].str)! = EOF) {Arr[cnt].len = strlen (ARR[CNT].STR);        cnt++;         } max = min = Arr[0].len; for (i = 0;i < cnt;i++) {if (min > Arr[i].len) {min = ar                R[i].len;                } if (Max < Arr[i].len) {max = Arr[i].len;                        }} for (i = 0;i < cnt;i++) {if (Arr[i].len = = min) {                printf ("%s\n", arr[i].str);                        }} for (i = 0;i < cnt;i++) {if (Arr[i].len = = max) {                printf ("%s\n", arr[i].str);    }        }    return 0;} 






Huazhong University of Science and Technology _2008___ postgraduate Computer _ Second interview machine

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.