Integer Game (UVA11489) 3 multiple, integeruva11489

Source: Internet
Author: User

Integer Game (UVA11489) 3 multiple, integeruva11489
K-Integer Game

Time Limit:1000 MSMemory Limit:0 KB64bit IO Format:% Lld & % llu

Submit Status Practice ultraviolet A 11489

 

 

 

 

In n, the number is a multiple of 3. If not, the result fails. Thought: if you can make the current number a multiple of 3, the number and must be a multiple of 3. To maintain this state, the remainder of each bitwise is obtained first, and the count of cnt [0], cnt [1], cnt [2]; is calculated, whether or not the entire string can be divisible by 3 depends on ans = (cnt [1] + cnt [2] * 2) % 3; the situation is discussed. If the entire string can be divisible, determine the number of cnt [0]. If it is an even number, T; otherwise, S; if it cannot be divisible, determine whether the number of cnt [ans] is greater than 0; <eg: 11111>; if the value is greater than 0, the number of cnt [0] is an even number. Otherwise, T; if the value is equal to 0, T; always in the 11111 condition! O (︶ ︿ ︶) o alas reprinted please indicate the source: Search for &

 

 1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5     int T,len,ca=1; 6     scanf("%d",&T); 7     char a[10005]; 8  9     while(ca<=T)10     {11         scanf("%s",a);12         len=strlen(a);13         int cnt[3]={0,0,0};14         for(int i=0;i<len;i++)15         {16             int tp=a[i]-'0';17             cnt[tp%3]++;18         }19         printf("Case %d: ",ca++);20         int mo=(cnt[1]+cnt[2]*2)%3;21         if(mo)22         {23             if(cnt[mo]>0)//1111124             {25                 if(cnt[0]&1) printf("T\n");26                 else printf("S\n");27             }28             else29             {30                 printf("T\n");31             }32         }33         else34         {35             if(cnt[0]&1) printf("S\n");36             else printf("T\n");37         }38     }39     return 0;40 }

 

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.