L1-1 寻找250
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
int x,sum=0;
while(~scanf("%d",&x))
{
sum++;
if(x!=250) continue;
else break;
}
printf("%d",sum);
return 0;
}
L1-2 日期格式化
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
int y,m,d;
char c;
scanf("%d%c%d%c%d",&m,&c,&d,&c,&y);
printf("%04d-%02d-%02d",y,m,d);
return 0;
}
L1-3 阅览室
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
struct ac{
int flag;
int m;
int w=0;
}a[N];
int main()
{
int n;
double sum=0;
int cnt=0,q=0;
cin>>n;
//getchar();
while(cnt<n)
{
int id,h,f;
char c,ch;
scanf("%d%c%c%c%d%c%d",&id,&ch,&c,&ch,&h,&ch,&f);
if(id==0) {
cnt++;
if(q==0) sum=0;
else
sum=1.0*sum/q;
printf("%d %.0lf\n",q,sum);
sum=0;
q=0;
for(int i=0;i<1005;i++)
{
a[i].w=0;
a[i].flag=0;
a[i].m=0;
}
}
if(c=='S')
{
a[id].flag=1;
a[id].m=h*60+f;
a[id].w++;
}
else if(c=='E'&&a[id].flag==1)
{
sum+=h*60+f-a[id].m;
a[id].flag=0;
q++;
}
}
}
L1-4 稳赢
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
int x,sum=0;
cin>>x;
while(1)
{
string s;
cin>>s;
if(s=="End") break;
else {
if(sum==x)
{
cout<<s<<endl;
sum=0;
}
else {
if(s=="ChuiZi") cout<<"Bu"<<endl;
else if(s=="Bu" ) cout<<"JianDao"<<endl;
else cout<<"ChuiZi"<<endl;
sum++;
}
}
}
}
L1-6 整除光棍
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
vector<int > ve;
int dived(vector<int> v, int n) {
int b = 0;
for(int i = 0; i < v.size(); i++) {
b = b * 10 + v[i];
ve.push_back(b / n);
b = b % n;
}
if(b == 0) return 0;
return 1;
}
int main() {
int n, flag = 0;
cin >> n;
string s;
for(int i = 0;; i++) {
s = s + '1';
vector<int> v;
for(int i = 0; i < s.size(); i++) {
v.push_back(s[i] - '0');
}
if(dived(v, n) == 0) {
reverse(ve.begin(), ve.end());
while(ve.size() > 1 && ve.back() == 0) ve.pop_back();
reverse(ve.begin(), ve.end());
flag = 1;
for(int i = 0; i < ve.size(); i++) {
cout << ve[i];
}
cout << " " << v.size();
}
ve.clear();
if(flag == 1) break;
}
}
L1-7 装睡
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int main()
{
int x;
cin>>x;
for(int i=0;i<x;i++)
{
int flag=0;
string s;
int a,b;
cin>>s>>a>>b;
if(a<15||a>20) flag=1;
if(b<50||b>70) flag=1;
if(flag==1) cout<<s<<endl;
}
}
L1-8 矩阵A乘以B
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int a[N][N],b[N][N],c[N][N];
int main()
{
int ra,rb,ca,cb;
cin>>ra>>ca;
for(int i=0;i<ra;i++)
{
for(int j=0;j<ca;j++)
cin>>a[i][j];
}
cin>>rb>>cb;
for(int i=0;i<rb;i++)
{
for(int j=0;j<cb;j++)
cin>>b[i][j];
}
if(ca==rb)
{
for(int i=0;i<ra;i++)
{
for(int j=0;j<cb;j++)
{
int sum=0;
for(int q=0,p=0;q<ca,p<rb;q++,p++)
{
sum=sum+a[i][q]*b[p][j];
}
c[i][j]=sum;
}
}
cout<<ra<<" "<<cb<<endl;
for(int i=0;i<ra;i++)
{
for(int j=0;j<cb;j++)
{
if(j!=0) cout<<" ";
cout<<c[i][j];
}
cout<<endl;
}
}
else {
cout<<"Error: "<<ca<<" != "<<rb<<endl;
}
}