本文主要是介绍ACM 第八届山东省赛 I Parity check SDUT 3901,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目再现链接: 点击打开链接
Parity check
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
找规律, 会发现%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;
}
这篇关于ACM 第八届山东省赛 I Parity check SDUT 3901的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!