CodeForces 375A Divisible By Seven

Source: Internet
Author: User

Divide this string of numbers into three parts: "1689", "0", and "others.

In the third part, * 10000 is used to obtain the remainder of 7, and then the remainder of the third part is used in the case of "1689". Finally, all 0 values are output.

The first time I did this kind of question, I had no idea at all. It was all taken by senior students .....

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     #include 
     
      #include 
      
       #define LL long longusing namespace std;char s[1001000];char w[1001000];bool mark[11];int main(){ memset(mark,false,sizeof(mark)); LL top = 0,sum = 0,i,Zero = 0; cin>>s; int len = strlen(s); for(i = 0;i < len; ++i) { if((s[i] == '1' || s[i] == '6' || s[i] == '8' || s[i] == '9') && mark[s[i]-'0'] == false) { mark[s[i]-'0'] = true; } else if(s[i] == '0') { Zero ++; } else { w[top++] = s[i]; } } for(i = 0;i < top; ++i) { sum *= 10; sum += (w[i]-'0'); sum %= 7; } sum *= 10000; sum %= 7; for(i = 0;i < top; ++i) { printf("%c",w[i]); } switch(sum) { case 0:printf("1869");break;// case 6:printf("1968");break; case 5:printf("1689");break;// case 4:printf("6198");break; case 3:printf("8691");break; case 2:printf("9861");break;// case 1:printf("8196");break;// } while(Zero--) { printf("0"); } cout<
       
        

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.