ACM 第八届山东省赛 I Parity check SDUT 3901
题目再现链接: 点击打开链接
Parity check
Time Limit: 2000MS Memory Limit: 524288KB
Problem Description
Fascinated with the computer games, Gabriel even forgets to study. Now she needs to finish her homework, and there is an easy problem:
f(n)=
She is required to calculate f(n) mod 2 for each given n. Can you help her?
Input
Multiple test cases. Each test case is an integer n(0≤n≤) in a single line.
Output
For each test case, output the answer of f(n)mod2.
Example Input
2
Example Output
1
Hint
Author
“浪潮杯”山东省第八届ACM大学生程序设计竞赛(感谢青岛科技大学)
找规律, 会发现%2 每三位 都是0 1 1 因此 看是 %3 余几即可 但又因为是10^1000 因此是个大数 ,大数处理 就行
#include <iostream> #include <algorithm> #include <cmath> #include <cstring> #include <stdio.h> #include <string> using namespace std; int main() { string s; int sum=0; int i; while(cin>>s) { int len=s.length(); sum=0; for(i=0;i<len;i++) { sum+=(s[i]-'0')%3; } sum%=3; switch(sum) { case 1:printf("1\n");break; case 0:printf("0\n");break; case 2:printf("1\n");break; } } return 0; }
岂曰无衣?与子同袍。王于兴师,修我戈矛。与子同仇!
岂曰无衣?与子同泽。王于兴师,修我矛戟。与子偕作!
岂曰无衣?与子同裳。王于兴师,修我甲兵。与子偕行!