first question
Title Description
A statement to the English word units reverse emissions. For example "I am a boy", after reverse emissions "boy a am I"
separated by a space between all the words, statements in addition to the letters, no longer contains the other characters
Interface Description
/ **
* inversion sentence
*
original sentence * @param sentence
sentence after inversion @return *
* /
public String Reverse (String sentence);
Enter a description:
A statement to the English word units reverse emissions.
Output Description:
Get the sentence in reverse order
Example 1
Entry
I am a boy
Export
boy a am I
Code:
#include<stdio.h>
int main()
{
char str[1000];
gets(str);
int i=strlen(str)-1;
for(;i>=0;i--)
{
if(str[i]==' ')
{
for(int j=i+1;str[j]!=' '&&str[j]!='\n'&&str[j]!='\0';j++)
{
printf("%c",str[j]);
}
printf(" ");
}
}
for(i=0;str[i]!=' '&&str[i]!='\n'&&str[i]!='\0';i++)
{
printf("%c",str[i]);
}
return 0;
}
The second question
Title Description
Given n strings, the arrangement of n strings in lexicographic order.
Enter a description:
A first input acts a positive integer n (1≤n≤1000), n n behavior following string (string length ≤100), the string contains only lowercase letters.
Output Description:
N data output lines, the output is arranged in a lexicographic order strings.
Example 1
Entry
9 cap to cat card two too up boat boot
Export
boat boot cap card cat to too two up
Code:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char strarr[n][100];
char temp[100];
for(int i=0;i<n;i++)
{
scanf("%s",strarr[i]);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(strcmp(strarr[j],strarr[j+1])>0)
{
strcpy(temp,strarr[j]);
strcpy(strarr[j],strarr[j+1]);
strcpy(strarr[j+1],temp);
}
}
}
for(int i=0;i<n;i++)
{
printf("%s\n",strarr[i]);
}
return 0;
}
The third question
Title Description
Enter a positive integer int type, int is calculated by number of the type of data stored in the memory 1.
Enter a description:
Enter an integer (int type)
Output Description:
This converted to a binary number, the number of output 1
Example 1
Entry
5
Export
2
Code:
#include<stdio.h>
int main()
{
int inp;
scanf("%d",&inp);
int num=0;
while(inp>0)
{
int rest=inp%2;
if(rest==1)
{
num++;
}
inp=inp/2;
}
printf("%d",num);
return 0;
}
Fourth Question
Title Description
Obviously want to invite some students in the school together to do a survey, in order to test the objectivity, his first with the computer-generated random integer (N≤1000) between 1 and 1000 N number, for which duplicate numbers, only a reservation, to remove the remaining the same number, corresponding to the number of different students learn different number. Then put these numbers in ascending order, to get the students to do research in accordance with good row order. Please help obviously complete "de-duplication" and "sort" work (with a test case where there may be multiple sets of data, we hope to be able to handle correctly).
Input Param
n number of input random numbers
InputArray n array of random integers
Return Value
Random integer output processing after OutputArray
Note: The test cases to ensure the correctness of the input parameters, respondents without authentication. More than one set of test cases.
Sample input explain:
There are two sets of test sample
The first group of three digits, are: 2.2.1.
11 is a second set of numbers, namely: 10,20,40,32,67,40,20,89,300,400,15.
Enter a description:
Multi-line input, the first input of the random integer number, then enter the corresponding number integer
Output Description:
The results return multiple rows, after treatment
Example 1
Entry
3 2 2 1 11 10 20 40 32 67 40 20 89 300 400 15
Export
1 2 10 15 20 32 40 67 89 300 400
Code:
#include<stdio.h>
int main()
{
int inter[1001];
int t;
while(scanf("%d",&t)!=EOF)
{
for(int i=0;i<1001;i++)
inter[i]=0;
for(int i=0;i<t;i++)
{
int n=0;
scanf("%d",&n);
inter[n]=1;
}
for(int i=1;i<=1000;i++)
{
if(inter[i]==1)
{
printf("%d\n",i);
}
}
}
return 0;
}
The fifth question
Title Description
• continuous input string, by the length of the output string array to a new resolution after each string 8;
• 8 is not an integer multiple of the length of a string of numbers 0 Please back up, not the empty string processing.
Enter a description:
Continuous input character string (input 2 times, each string length is less than 100)
Output Description:
Is output to the length of the new string array 8
Example 1
Entry
abc 123456789
Export
abc00000 12345678 90000000
Code:
#include<stdio.h>
#include <string.h>
int main()
{
char str[100];
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
for(int i=0;i<len;i++)
{
if((i+1)%8==0)
{
printf("%c\n",str[i]);
}
else
{
printf("%c",str[i]);
}
}
int pud=8-len%8;
if(pud!=8)
{
for(int i=0;i<pud;i++)
{
printf("%c",'0');
}
printf("\n");
}
}
return 0;
}