1120 Friend Numbers

题目大意是求一些数字的各位和,看一下有多少不同的,并且按升序输出,水题~

#include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#define maxn 10005
#define INF 0x3f3f3f3f
#define EPS 1e-6
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
int n,x,sum;
int a[maxn],b[maxn],vis[maxn];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        sum=0;
        scanf("%d",&x);
        while(x)
        {
            sum+=x%10;
            x=x/10;
        }
        a[i]=sum;
    }
    sort(a,a+n);
    int p=unique(a,a+n)-a;
    printf("%d\n",p);
    printf("%d",a[0]);
    for(int i=1;i<p;i++)
    {
        printf(" %d",a[i]);
    }

    printf("\n");
}

原文地址:https://www.cnblogs.com/FTA-Macro/p/10305900.html

时间: 2024-08-30 17:54:22

1120 Friend Numbers的相关文章

PAT 1120 Friend Numbers[简单]

1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend I

1120 Friend Numbers (20 分)

1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend I

1120 Friend Numbers (20)

Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you

PAT 甲级 1120 Friend Numbers

1 #include <iostream> 2 #include <cstring> 3 int a[10000]; 4 int max1=0, n=0; 5 int first = 0; 6 using namespace std; 7 8 void bijiao() 9 { 10 int i; 11 for (i=1;i<=max1; i++) 12 { 13 if (a[i]>=1) 14 { 15 n++; 16 } 17 } 18 } 19 void shuc

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

Timus 1120. Sum of Sequential Numbers 数学题

There is no involute formulation concerning factitiously activity of SKB Kontur in this problem. Moreover, there is no formulation at all. Input There is the only number N, 1 ≤ N ≤ 109. Output Your program is to output two positive integers A and P s

HDoj-1058-Humble Numbers

Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17723    Accepted Submission(s): 7706 Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble numb

ITI 1120 - Assignment

ITI 1120 - Assignment 1Submit a zip file with a1q1.py, a1q2.py, a1q3.py, a1q4.py.1. (2 points) Two numbers a and b are called pythagorean pair if both a and b areintegers and there exists an integer c such that a2 + b2 = c2. Write afunction pythagore

LeetCode OJ - Sum Root to Leaf Numbers

这道题也很简单,只要把二叉树按照宽度优先的策略遍历一遍,就可以解决问题,采用递归方法越是简单. 下面是AC代码: 1 /** 2 * Sum Root to Leaf Numbers 3 * 采用递归的方法,宽度遍历 4 */ 5 int result=0; 6 public int sumNumbers(TreeNode root){ 7 8 bFSearch(root,0); 9 return result; 10 } 11 private void bFSearch(TreeNode ro