Sha 10152 ShellSort shell sorting (Hill sorting ?)

Source: Internet
Author: User

Today's status is always bad, and this type of question gets stuck for a day...

Is it because the rest time is too short and the mind is too dull...

The name is Hill sorting. I thought it was related to it, and I also searched for information.

If you find trick, you will find it a very watery question. You only need to compare the migrated shells and then output them.

Code:


 

#include <cstdio>  #include <cstring>  const int maxn = 1000; char pre[maxn][100], tar[maxn][100];  int main() {     int n; //  freopen("in", "r", stdin);      scanf("%d", &n);     while (n--) {         int m;         scanf("%d", &m);         gets(pre[0]);         for (int i = m - 1; i >= 0; i--)             gets(pre[i]);         for (int i = m - 1; i >= 0; i--)             gets(tar[i]);         int cnt = 0;         for (int i = 0, j = 0; i < m;) {             if (!strcmp(pre[i], tar[j]))                 i++, j++;             else                 i++, cnt++;         }//for          for (int i = m - cnt; i < m; i++)             printf("%s\n", tar[i]);         printf("\n");     }//while      return 0; } #include <cstdio>#include <cstring>const int maxn = 1000;char pre[maxn][100], tar[maxn][100];int main() { int n;// freopen("in", "r", stdin); scanf("%d", &n); while (n--) {  int m;  scanf("%d", &m);  gets(pre[0]);  for (int i = m - 1; i >= 0; i--)   gets(pre[i]);  for (int i = m - 1; i >= 0; i--)   gets(tar[i]);  int cnt = 0;  for (int i = 0, j = 0; i < m;) {   if (!strcmp(pre[i], tar[j]))    i++, j++;   else    i++, cnt++;  }//for  for (int i = m - cnt; i < m; i++)   printf("%s\n", tar[i]);  printf("\n"); }//while return 0;} 

 

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.