T1
#include
using namespace std; int main(){ int n; while(cin>>n&&n!=0){//连续输入 int a[n]; for(int i=0;i >a[i]; int count1=0,count2=0,m=a[0]; for(int i=0;i
T2
#include
#include using namespace std; int main(){ int n; cin>>n; for(int i=0;i >a; int num=0; for(unsigned int j=0;j
T3
#include
using namespace std; typedef long long ll; int day(string str) { int n; if(str=="monday")n=1; else if(str=="tuesday")n=2; else if(str=="thursday")n=4; else if(str=="wednesday")n=3; else if(str=="friday")n=5; else if(str=="saturday")n=6; else if(str=="sunday")n=7; return n; } int main() { ll t; string str1,str2; cin>>t; ll l,r; ll begin,end; for(int j=0; j >str1>>str2; cin>>l>>r; begin=day(str1); end=day(str2)+1; while(end-begin r)cout<<"impossible"< =l&&end-begin<=r) { key++; onlyday=end-begin; end+=7; } if(key==1)cout< 1)cout<<"many"<
T4
#include
#include
#include
#include
#include
T5
#include
#include
#include
using namespace std;
char let[4]={'<','(','[','{'};
char rit[4]={'>',')',']','}'};
int main(){
int n;
cin>>n;
while(n--){
string str;
cin>>str;
stack q;
for(int i=0;i
T6
#include
#include
#include
#include
#include
T10
#include
#include
#include
#include
using namespace std;
struct memory
{
int len;
int number;
bool Is_use=false;
memory(int L,int N)
{
len=L;
number=N;
Is_use=true;
}
};
bool cmp(const memory &l,const memory &r)
{
if(l.Is_use==r.Is_use)
{
return l.numberr.Is_use;
}
int main()
{
vector v;
vector::iterator it;
int num_of_block=1;
int lmemory;
int t,m;
cin>>t>>m;
lmemory=m;
while(t--)
{
string op;
int num;
cin>>op;
if(op=="alloc")
{
cin>>num;
if(lmemoryIs_use==false&&it->len>=num)
{
// cout<len-=num;
// //v.insert(it-1,memory(num,num_of_block));
// leftmemory-=num;
// num_of_block++;
// flag=true;
// break;
cout<len;
it->number=num_of_block;
it->Is_use=true;
it->len=num;
v.insert(it+1,memory(temp-num,-1));
lmemory-=num;
num_of_block++;
flag=true;
break;
}
}
if(!flag)
{
int sum=0;
for(it=v.begin();it!=v.end();it++)
{
sum+=it->len;
}
if(sum+num>m) cout<<"NULL"<>num;
bool flag=0;
for(it=v.begin();it!=v.end();it++)
{
if(it->number==num&&it->Is_use==true)
{
it->Is_use=false;
flag=true;
lmemory+=it->len;
break;
}
}
if(!flag) cout<<"ILLEGAL_ERASE_ARGUMENT"<Is_use==false)
{
lmemory+=it->len;
v.erase(it);
it--;
}
}
}
system("pause");
return 0;
}
T11
#include
using namespace std;
int main() {
for (int i = 0; i < 100; i++) {
int n;
double sum=0;
cin>>n;
double x=0;
int y=0;
if(n==NULL) break;
if(n==0) continue;
double num[n];
for (int j = 0; j < n; j++) {
cin>>num[j];
sum+=num[j];
}
double m=sum/n;
for (int j = 0; j < n; j++) {
x+=(num[j]-m)*(num[j]-m);
}
y=x/n;
cout<
T12
#include
using namespace std;
int main() {
int n,num=0;
cin>>n;
for (int i =0;i0){
s[j]=t%2+48;
t/=2;
j--;
}
for(int j=0;j<8;j++){
if(s[j]=='1') num++;
}
s="00000000";
}
cout << num<< endl;
num=0;
}
return 0;
}
T13
#include
#include
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector res(m,0);
vector > map(m);
for(int i=0;i>s;
for(int j=0;j
T14
#include
using namespace std;
int main()
{
int n;
cin>>n;
int x, y;//坐标
int l = 0, r = 0;//左右的数量
for (int i = 0; i < n; i++)
{
cin >> x >> y;
if (x < 0) //统计左右的点的个数
l++;
else
r++;
}
if (l <= 1 || r <= 1)//存在小于1的
cout << "Yes";
else
cout << "No";
}
T15
#include
#include
#include
using namespace std;
string reverseWords(string sentence) {
stringstream ss(sentence);
string word;
string reversedSentence;
while (ss >> word) {
for (int i = word.length() - 1; i >= 0; i--) {
reversedSentence += word[i];
}
reversedSentence += " ";
}
return reversedSentence.substr(0, reversedSentence.length() - 1);
}
int main() {
int N;
cin >> N;
cin.ignore(); // 忽略第一行末尾的换行符
for (int i = 0; i < N; i++) {
string sentence;
getline(cin, sentence);
string reversedSentence = reverseWords(sentence);
cout << reversedSentence << endl;
}
return 0;
}
T16
#include
#include
#include
#include
#include//某种字符串流基类
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
stringstream ss3;
ss3<=0)cout<
T17
#include
#include
#include
#include
#include//某种字符串流基类
#include
using namespace std;
struct st{
string name;
int numb;
};
bool cmp(st st1,st st2){
return st1.numb>n>>m;
cin.ignore();
st arr[m];
for (int i = 0; i < m; i++) {
string str;
getline(cin,str);
int num=0;
for (int j = 0; j < n; j++) {
for (int k = j+1; k < n; k++) {
if (str[k]-str[j]<0) num++;
}
}
arr[i].name=str;
arr[i].numb=num;
}
sort(arr, arr+m, cmp);
for (int i = 0; i < m; i++) {
cout<
T18
#include
#include
#include
using namespace std;
double calculateArea(double x1, double y1, double x2, double y2, double x3, double y3) {
double area = 0.5 * abs((x1 - x3) * (y2 - y3) - (x2 - x3) * (y1 - y3));
return area;
}
int main() {
while (true) {
double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
// 判断是否输入结束
if (x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0 && x3 == 0 && y3 == 0) {
break;
}
double area = calculateArea(x1, y1, x2, y2, x3, y3);
cout << fixed << setprecision(6) << area << endl;
}
return 0;
}
T19
#include
#include
using namespace std;
int main()
{
string str1;
cin>>str1;//读入字符串
long long int n;
stringstream ss;
ss<>n;//转化为整型,为了后面的计算
ss.clear();//一定要记得clear
int count=str1.length();
str1=str1+str1;
bool flag=true;
for(int i=1;i<=count;i++)
{
flag=1;
long long int m=n*i;
string strm;
ss<>strm;
ss.clear();
int p=str1.find(strm);
if(p==-1)
{
flag=0;
break;
}
}
if(flag==1) cout<<"Yes"<
T20
#include
using namespace std;
int main() {
int n, P1, P2, P3, T1, T2;
std::cin >> n >> P1 >> P2 >> P3 >> T1 >> T2;
int totalPower = 0;
int previousEndTime = 0;
for (int i = 0; i < n; i++) {
int startTime, endTime=0;
cin >> startTime >> endTime;
int workTime = endTime - startTime;
totalPower += workTime * P1;
if ((startTime-previousEndTime>0)&&i>0){
int time=min(startTime-previousEndTime, T1);
totalPower += time * P1;
if (startTime-previousEndTime> T1) {
int screenSaverTime = min(startTime-previousEndTime-T1, T2);
totalPower += screenSaverTime * P2;
if (startTime-previousEndTime > T2) {
int sleepTime = startTime-previousEndTime-T2-T1;
totalPower += sleepTime * P3;
}
}
}
previousEndTime = endTime;
}
std::cout << totalPower << std::endl;
return 0;
}
T21
#include
#include
using namespace std;
// 函数:计算校验码
int calculateChecksum(string number, int base) {
int sum = 0;
// 将B进制转换为十进制
for (char digit : number) {
if (digit >= 'a' && digit <= 'f') {
sum += digit - 'a' + 10;
} else {
sum += digit - '0';
}
}
// 判断数字和是否被B-1整除
if (sum % (base - 1) == 0) {
return 0;
} else {
int checksum = (base - 1) - sum % (base - 1);
return checksum;
}
}
int main() {
int t;
cin >> t;
while (t--) {
int base;
string number;
cin >> base >> number;
int checksum = calculateChecksum(number, base);
if(checksum<10) {
cout << checksum << endl;
} else if (checksum==10) cout << 'a' << endl;
else if (checksum==11) cout << 'b' << endl;
else if (checksum==12) cout << 'c' << endl;
else if (checksum==13) cout << 'd' << endl;
else if (checksum==14) cout << 'e' << endl;
else if (checksum==15) cout << 'f' << endl;
}
return 0;
}
T18-三角形面积
#include
#include #include using namespace std; double calculateArea(double x1, double y1, double x2, double y2, double x3, double y3) { double area = 0.5 * abs((x1 - x3) * (y2 - y3) - (x2 - x3) * (y1 - y3)); return area; } int main() { while (true) { double x1, y1, x2, y2, x3, y3; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; // 判断是否输入结束 if (x1 == 0 && y1 == 0 && x2 == 0 && y2 == 0 && x3 == 0 && y3 == 0) { break; } double area = calculateArea(x1, y1, x2, y2, x3, y3); cout << fixed << setprecision(6) << area << endl; } return 0; } 注意输出的小数点精度,用cout << fixed << setprecision(6) << area << endl;控制
T19-循环数
#include
#include using namespace std; int main() { string str1; cin>>str1;//读入字符串 long long int n; stringstream ss; ss< >n;//转化为整型,为了后面的计算 ss.clear();//一定要记得clear int count=str1.length(); str1=str1+str1; bool flag=true; for(int i=1;i<=count;i++) { flag=1; long long int m=n*i; string strm; ss< >strm; ss.clear(); int p=str1.find(strm); if(p==-1) { flag=0; break; } } if(flag==1) cout<<"Yes"< 把数直接复制两份拼接一下,142857变成142857142857,再用find判断