题目
9 is a lucky number in the chinese traditional culture. This problem gives you an integer number, whose absolute value is not larger than 10^1000000, and your task is calculating the integer mod 9.
题目大意是给你一个大数,问其mod9的结果
思路
待填坑
代码
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
char str[999];
cin >> str;
int i = 0;
int k = 0;
int j = 0;
int num = 9;
int a[999];
const char* ptr = str;
while (j < strlen(str)) {
a[j] = str[j++]-48 ;
}
while (k < j) {
if (i + a[k] < num) {
i = a[k];
if (k != j - 1)i = i*10;
k++;
}
if (i + a[k] > num) {
i = (i + a[k]) % num;
if (k == j-1) break;
i = i * 10;
k++;
}
if (i + a[k] == num) {
i = 0;
k++;
}
}
cout << i<< " ";
return 0;
}