PAT1120 Friend Numbers 找朋友(STL-SET)

如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。

例如 123和 51就是朋友数,因为 1+2+3=5+1=6,而 6 就是它们的朋友证号。

给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。

 

思路:输入时用字符串加起来方便,用set可以直接去重。

#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 0x3f3f3f;
using namespace std;
const int N=1e5+233;
int n;
set<int>s;
int gao(string str){
    int res=0;
    rep(i,0,str.length()) res+=str[i]-'0';
    return res;
}
int main(){
    cin>>n;
    string str;
    rep(i,0,n){
        cin>>str;
        s.insert(gao(str));
    }
    cout<<s.size()<<endl;
    int flag=0;
    for(auto u:s){
        if(flag) cout<<" ";
        cout<<u;
        flag++;
    }
    cout<<endl;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Python以及Flask的微型本地Arcaea服务器.zip 特性 Features :x: : 不支持 Not supported :warning: : 可能存在问题 / 可能与官方不一样 Possible issues / may differ from official :wastebasket: : 不再更新,可能会移除或重构 No longer updated, may be removed or refactored :construction: : 建设中 In construction 登录、注册 Login and registration 多设备自动封号 Auto-ban of multiple devices :warning: 多设备登录 Multi device login 登录频次限制 Login rate limit :x: 销号 Destroy account 成绩上传 Score upload 成绩校验 Score check 成绩排名 Score rank 潜力值机制 Potential Best 30 :warning: Recent Top 10 :warning: 世界排名 Global rank 段位系统 Course system :warning: Link Play 好友系统 Friends :x: 好友位提升 Max friend number increase 云端存档 Cloud save 尝试全剧情、曲目解锁 Try to unlock all the stories and songs 世界模式 World mode 体力系统 Stamina system :warning: 普通梯子强化和绳子强化 Normal steps boost & beyond boost :warning: 角色技能 Character skills 歌曲下载 Songs downloading :x: 加密下载 Encrypted downloading 下载校验 Download check 下载频次限制 Download rate limit 购买系统 Purchase system 单曲和曲包 Single & Pack :x: 捆绑包 Bundle 折扣 Discount 五周年兑换券 5-th anniversary ticket :x: Extend 包自动降价 Extend pack automatic price reduction 奖励系统 Present system 兑换码系统 Redeem code system 角色系统 Character system 数据记录 Data recording 用户成绩 Users' scores 用户每日潜力值 Users' daily potential :wastebasket: 简单的网页管理后台 Simple web admin backend :construction: API 服务器日志 Server log

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值