C++
#include <iostream>
using namespace std;
int main(void)
{
int n, sum;
sum = 0;
cin >> n;
for (int i = 1; i <= n; i++)
sum += i;
cout << sum << endl;
return (0);
}
Python
n = int(input())
sum = 0
for i in range (n + 1):
sum = sum + i
print(sum)
C++
#include <iostream>
using namespace std;
int main(void)
{
int n, a, b, sum;
cin >> n;
for (int i = 1; i <= n; i++)
{
sum = 0;
cin >> a >> b;
sum = a + b;
cout << "Case #" << i << ": " << sum << "\n";
}
return (0);
}
Python
n = int(input())
for i in range (n):
a,b = map(int, input().split())
sum = a + b
print("Case #%s: %s"%(i+1, sum))
C++
#include <iostream>
using namespace std;
int main(void)
{
int n, r;
string str;
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> r >> str;
for (int j = 0; j < str.length(); j++)
{
for (int k = 0; k < r; k++)
{
cout << str[j];
}
}
cout << endl;
}
return (0);
}
Python
n = int(input())
for i in range(n):
r, str = input().split()
for j in str:
print(j*int(r), end="")
print() //줄바꿈
C++
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int n;
cin >> n;
for(int i = n; i > 0; i--)
{
cout << i << "\n";; //endl을 사용하면 버퍼 비워내야해서 시간초과 뜬다.
}
return (0);
}
Python
n = int(input())
for i in range (n):
print(n - i)
C++
#include <iostream>
using namespace std;
double get_sum(int max, double* score, int n)
{
double sum = 0;
for (int j = 0; j < n; j++)
{
score[j] = score[j] / max * 100;
sum += score[j];
}
return (sum / n);
}
int main(void)
{
int n;
double score[1000] = {}, avg = 0, max = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> score[i];
if (max < score[i])
max = score[i];
}
avg = get_sum(max, score, n);
cout << fixed;
cout.precision(3);
cout << avg << endl;
return (0);
}
Python
n = int(input())
score = list(map(int, input().split()))
max = max(score)
for i in range(n):
score[i] = score[i] / max * 100
avg = sum(score) / n
print(round(avg,3))