Linux-related-handwriting test program

Source: Internet
Author: User
Tags diff

Because I am too weak,, and will not lemon,, and will not install lemon under Ubuntu, so I choose the handwriting test program emmmm

First of all, we need to know how to write this thing first.

1      for(inti =1; I <= +; i++)2     {3System"./make >in.in");4System"./work >out.out");5System"./work1 >out1.out");6         if(System ("diff-bb out.out out1.out"))7         {8printf"Error in%d\n", i);9              Break;Ten         } One         Else A         { -printf"passed ...%d\n", i); -System"Sleep 1"); the         } -}

Then our test program is based on this procedure.

Because the system is all strings, so we need to use the string, but how to use it?

We can use some small strings to cobble together a large string. such as this:

1         "  "".in";

where S and TMP are both strings.

TMP represents the number of data groups currently being tested.

Because usually our packet is this: 1.in 1.out 2.in 2.out ...

Because the suffix is the same, we just need to save the previous number with TMP. So how are we going to get it?

1 void Get(intx)2 {3tot =0;4      while(x) M[++tot] = x%Ten, x/=Ten;5TMP =" /";6      for(R i = tot; i; I--)7     {8TMP + = M[i] +'0';9     }Ten}

Because TMP is also a string, we can write a get function to put the number x into a string and put the TMP

It is worth noting that the initialization of the string can not be directly equal to 0, (although I see a lot of online blog is direct = 0, but I so use will error,, I do not know why);

So we make TMP = "n";

Then put the number in, and put it in the same way as before the addition of a small string.

So now we have a string that should be placed in system (""), so how do we put it in?

1      for(R i =1; I <=Ten; i++)2     {3         Get(i);4s ="./work <"+ tmp +". in";5 System (S.C_STR ());6s ="DIFF-BB a.out"+ tmp +". out";7         if(System (S.C_STR ()))8         {9printf"Get%d points\n", (I-1) *Ten);TenExit0);  One         } A}

We can use the. c_str () directly to get the first character address of the current string, and then place it where the string is originally needed, and take care not to "" Oh.

Put the complete code:

1#include <bits/stdc++.h>2 using namespacestd;3 #defineR Register int4 strings,tmp;5 intm[Ten], tot;6 7 void Get(intx)8 {9tot =0;Ten      while(x) M[++tot] = x%Ten, x/=Ten; OneTMP =" /"; A      for(R i = tot; i; I--) -     { -TMP + = M[i] +'0'; the     } - } -  - intMain () + { -      for(R i =1; I <=Ten; i++) +     { A         Get(i); ats ="./work <"+ tmp +". in"; - System (S.C_STR ()); -s ="DIFF-BB a.out"+ tmp +". out"; -         if(System (S.C_STR ())) -         { -printf"Get%d points\n", (I-1) *Ten); inExit0);  -         } to     } +printf"Get points!!!?? \ n"); -     return 0; the}

The expression above is just to sell the O__o "...

Linux-related-handwriting test program

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.