problem_3


Problem_3
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description

第一学期已经接近尾声了,通往寒假的大门由八位Exam把守。这里的Exam收藏了一个数字,但这个数字太长了,他想要把这个数字压缩成个位数。

例如:

666

第一次合成是6 +6 +6 =18;

第二次合成是1+8=9是个位数,合成结束。


压缩的方式是把数字的每一位相加,会得到一个新数字,然后再对新数字进行相同的操作。直到最后得到一个个位数。如果你能帮他实现这个愿望,他就放你通过。

Input

多组输入
每组一个n,表示待压缩的数字,数字的位数保证小于1000,即数字范围为0<=n<=10^1000
Output

输出压缩后得到的个位数。
Example Input

99
233
666
Example Output

9
8
9
#include<stdio.h>
int main()
{
char a[1100];
int i,j,s,n;
while(~scanf("%s",a))
{
for(i=s=0; a[i]; i++)
s=s+a[i]-'0';
while(s>9)
{
n=s;
s=0;
while(n>0)
{
s=s+(n%10);
n=n/10;
}
}
printf("%d\n",s);
}
return 0;
}

在 `fetchDataCft` 函数中, `resolve` 方法只接受一个参数,所以需要将 `data` 和 `total_count` 封装为一个对象传递。修改后的 `fetchDataCft` 函数如下: ``` export function fetchDataCft(query_dict) { return new Promise((resolve, reject) => { queryCft(query_dict) .then(response => { const data = response.data; const total_count = response[&#39;total_count&#39;]; resolve({ data, total_count }); }) .catch(error => { reject(error); }); }); } ``` 在 `getData` 函数中,当 `Object.keys(this.query_dict_mark).length === 0` 时,会调用 `fetchDataCft` 函数,但是这个函数返回的是一个 Promise,需要使用 `then` 方法来处理异步操作。修改后的代码如下: ``` getData() { if (Object.keys(this.query_dict_mark).length === 0) { // 初始化query_dict中problem_id__in的值 this.$delete(this.query_dict, &#39;problem_id__in&#39;); fetchDataCft(this.query_dict) .then(({ data, total_count }) => { this.data_list = data; this.total_count1 = total_count; }) .catch(error => { console.error(error); }); } else { fetchDataMark(this.query_dict_mark) .then(data => { this.problem_id_list = data.map(item => item.problem_id); this.$set(this.query_dict, &#39;problem_id__in&#39;, this.problem_id_list); // this.query_dict[&#39;problem_id__in&#39;] = this.problem_id_list fetchDataCft(this.query_dict) .then(({ data, total_count }) => { this.data_list = data; this.total_count1 = total_count; }) .catch(error => { console.error(error); }); }) .catch(error => { console.error(error); }); } // 获取当前用户的收藏列表(problem_id_favorite) fetchDataMark({ favorite: this.current_user_name }) .then(data => { this.problem_id_favorite = data.map(item => item.problem_id); }) .catch(error => { console.error(error); }); }, ``` 这样,无论是在 `fetchDataCft` 函数中还是在 `getData` 函数中,都能够正确地处理异步操作,避免出现不符合预期的结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值