One: The order of words in an English sentence is reversed and then output. For example, enter "How IS is" and output "how do you"
#include <stdio.h>
int main ()
{
Char sentence[100];
int len=0,j,wordlen=0;
Gets (sentence);
while (Sentence[len]) len++;
for (j=len-1;j>=0;j--)
{
if (sentence[j]>= ' a ' &&sentence[j]<= ' Z ' | | sentence[j]>= ' A ' &&sentence[j]<= ' Z ')
{
wordlen++;
}
else if (wordlen>0)
{
printf ("%*.*s", wordlen,wordlen,&sentence[j+1]);
printf ("%c", Sentence[j]);
wordlen=0;
}
Else
printf ("%c", Sentence[j]);
}
if (wordlen>0) printf ("%*.*s", wordlen,wordlen,sentence);
return 0;
}
Two: Write a program that parses the frequency of occurrences of each word in a string and displays the word and the frequency at which it appears.
Package test;
Import java.util.ArrayList;
Import java.util.Collections;
Import Java.util.Comparator;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Java.util.Map.Entry;
public class WJ {
public static void Main (string[] args) {
String str = "Hello World My first Unit Test";
string[] items = Str.split ("");
map<string, integer> map = new hashmap<string, integer> ();
for (String S:items) {
if (Map.containskey (s))
Map.put (S, map.get (s) + 1);
else {
Map.put (S, 1);
}
}
list<entry<string, integer>> list = new arraylist<entry<string, integer>> ();
For (entry<string, integer> entry:map.entrySet ()) {
List.add (entry);
}
Collections.sort (list, new Entrycomparator ());
For (entry<string, integer> obj:list) {
System.out.println (Obj.getkey () + "\ T" + obj.getvalue ());
}
}
}
Class Entrycomparator implements Comparator<entry<string, integer>> {
public int Compare (entry<string, integer> O1, entry<string, integer> O2) {
return O1.getvalue () > O2.getvalue ()? 0:1;
}
}
Software Test second Job