L1-001-Hello World
#include<bits/stdc++.h>
using namespace std;
int main()
{
printf("Hello World!\n");
return 0;
}
L1-002-打印沙漏
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
char c;
scanf("%d %c",&n,&c);
int m = 0x3f3f3f3f;
int res;
int h;
for(int i = 1 ; i < 30; i++)
{
int x = 2 * i * i - 1;
if(n - x < 0) break;
if(n - x < m ) { res = x , m = n - x , h = i;}
}
int t = (h - 1) * 2 + 1;
for(int i = 1 ; i <= h; i++)
{
for(int k = 1 ; k <= i - 1 ; k++)
{
printf(" ");
}
for(int j = 1 ; j <= 2 * h - 2 * i + 1 ; j++)
{
printf("%c",c);
}
printf("\n");
}
h = t - h;
for(int i = 1 ; i <= h ; i++)
{
for(int k = 1 ; k <= h - i ; k++)
{
printf(" ");
}
for(int j = 1 ; j <= 2 * i + 1 ; j++)
{
printf("%c",c);
}
printf("\n");
}
printf("%d\n",n-res);
return 0;
}
L1-003-个位数统计
#include<bits/stdc++.h>
using namespace std;
const int N = 11;
int s[N];
int main()
{
string str;
cin>>str;
for(int i = 0 ; i < str.size() ; i++)
{
int x = str[i] - '0';
s[x]++;
}
for(int i = 0 ; i <= 9 ; i++)
{
if(s[i])
{
printf("%d:%d\n",i,s[i]);
}
}
return 0;
}
L1-004-计算摄氏温度
#include<bits/stdc++.h>
using namespace std;
int main()
{
int f;
cin>>f;
printf("Celsius = %d",5 * (f - 32) / 9);
return 0;
}
L1-005-考试座位号
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<string , int> pii;
map <int,pii> m;
int main()
{
int N;
cin>>N;
string s;
int idx;
int d;
for(int i = 0 ; i < N ; i++)
{
cin>>s>>idx>>d;
m[idx].fi = s;
m[idx].se = d;
}
int M;
cin>>M;
for(int i = 0 ; i < M ; i++)
{
int x;
cin>>x;
cout<<m[x].fi<<" "<<m[x].se<<endl;
}
return 0;
}