AtCoder Beginner Contest 281 A~C

A - Count Down

#include 

using namespace std;

int main() {
	int n;
	cin >> n;
	for(int i = n; i >= 0; i--) cout << i << endl;

	return 0;
}

B - Sandwich Number

#include 

using namespace std;

int main() {
	string s;
	cin >> s;
	if(s[0] >= 'A' && s[0] <= 'Z' && s[s.size()-1] >= 'A' && s[s.size()-1] <= 'Z') {
		string t = s.substr(1, 6);
		if(t >= "100000" && t <= "999999") cout << "Yes";
		else cout << "No";
	}
	else cout << "No";

	return 0;
}

C - Circular Playlist

两种情况:
1.至少能循环一遍全部的歌曲
2.一遍都无法全部播完

#include 

using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
ll a[N];

int main() {
	ll n, t, s = 0;
	cin >> n >> t;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}

	if(t / s) {
		ll tt = t % s;
		for(int i = 0; i < n; i++) {
			if(tt - a[i] > 0) tt -= a[i];
			else {
				cout << i + 1 << " " << tt;
				break;
			}
		}
	}
	else {
		for(int i = 0; i < n; i++) {
			if(t - a[i] > 0) t -= a[i];
			else {
				cout << i + 1 << " " << t;
				break;
			}
		}
	}

	return 0;
}

你可能感兴趣的:(AtCoder,c语言,c++,算法)