第1题
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int a[n];
int sum = 0;
for(int i = 0; i < n; i++)
{
cin >> a[i];
sum += a[i];
}
cout << sum << endl;
return 0;
}
第2题
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int total = 2 * n - 1;
string s[total];
for(int i = 0; i < total; i++)
{
cin >> s[i];
}
for(int i = 0; i < total; i++)
{
int j = 0;
for(; j < total; j++)
{
if(i != j && s[i] == s[j])
{
break;
}
}
if(j == total)
{
cout << s[i] << endl;
return 0;
}
}
return 0;
}
第3题
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int discount = 0;
if(n >= 5000)
{
discount = 800 + 250 + 120;
}
else if(n >= 2000)
{
discount = 250 + 120 + 66;
}
else if(n >= 1000)
{
discount = 120 + 66 + 11;
}
else if(n >= 500)
{
discount = 66 + 11 + 1;
}
else if(n >= 100)
{
discount = 11 + 1;
}
else if(n >= 10)
{
discount = 1;
}
cout << n - discount << endl;
return 0;
}
少儿编程答疑、算法答疑请加微信307591841或QQ307591841
公众号.jpg
网友评论