https://www.acmicpc.net/problem/15596
방법 1 - 13740KB, 8ms, 148B
#include <vector>
long long sum(std::vector<int> &a) {
long long ans = 0;
for (int i = 0; i < a.size(); i++) {
ans += a.at(i);
}
return ans;
}
방법 2 - 13740KB, 24ms, 207B
#include <vector>
using namespace std;
long long sum(vector<int>& a) {
long long ans = 0;
for (vector<int>::iterator iter = a.begin(); iter < a.end(); iter++)
ans += *iter;
return ans;
}
https://www.acmicpc.net/problem/4673
방법 1 - 2020KB, 40ms, 345B
#include <iostream>
using namespace std;
int sum(int n) {
int m = n;
while (n) {
m += n % 10;
n /= 10;
}
return m;
}
int main() {
int d[10001] = {};
int t;
for (int i = 1; i <= 10000; i++) {
if (d[i] == 0) {
cout << i << endl;
t = i;
while (1) {
t = sum(t);
if (t > 10000) break;
d[t]++;
}
}
}
}
방법 2 - 2020KB, 40ms, 299B
#include <iostream>
using namespace std;
int sum(int n) {
int m = n;
while (n) {
m += n % 10;
n /= 10;
}
return m;
}
int main() {
int d[10001] = {};
int t;
for (int i = 1; i <= 10000; i++) {
if (d[i] == 0)
cout << i << endl;
t = sum(i);
if (t <= 10000)
d[t]++;
}
}
방법 3 - 1112KB, 0ms, 213B
#include<stdio.h>
int sum(int n){
int m=n;
while(n){
m+=n%10;
n=n/10;
}
return m;
}
int main(){
int k[10100]={};
for(int i=1; i<=10000; i++){
if(k[i]==0)
printf("%d\n",i);
k[sum(i)]=1;
}
}
https://www.acmicpc.net/problem/1065
방법 1 - 2020KB, 0ms, 401B
#include <iostream>
using namespace std;
int v(int n) {
int cnt = 0;
if (n < 100) cnt = n;
else if (n == 1000) cnt = v(999);
else if (100 <= n) {
cnt = 99;
for (int i = 100; i < n+1; i++) {
int c12 = (i % 100) / 10 - i % 10;
int c23 = i / 100 - (i % 100) / 10;
if (c12==c23) cnt++;
}
}
return cnt;
}
int main() {
int a;
cin >> a;
int cnt = v(a);
cout << cnt << "\n";
}
방법 2 - 1112KB, 0ms, 159B
#include <stdio.h>
int main(){
int n, cnt=0;
scanf("%d", &n);
for(int i=1; i<=n; i++){
if(i<100||i/100+i%10==2*((i%100)/10))cnt++;
}
printf("%d",cnt);
}