
洛谷刷题个人题解
刷刷刷
宋轻云
只有疯子和自律的人,才算活过
展开
-
力扣:剑指 Offer 50. 第一个只出现一次的字符
1、哈希表做法class Solution {public: char firstUniqChar(string s) { int hash[256]={0}; for(int i=0;s[i];++i) ++hash[s[i]]; for(int i=0;s[i];++i) if(hash[s[i]]==1) return s[i]; return ' '; }};原创 2021-11-13 20:02:52 · 232 阅读 · 0 评论 -
力扣:面试题 01.01. 判定字符是否唯一
1、哈希表做法class Solution {public: bool isUnique(string astr) { int cnt[256]={0}; for(int i=0;astr[i];++i) ++cnt[astr[i]]; for(int i=0;i<256;++i) if(cnt[i]>=2) return false; return true; }};...原创 2021-11-13 19:58:27 · 244 阅读 · 0 评论 -
洛谷:P1888 三角函数
1、#include<iostream>#include<cstdio>using namespace std;int main(){ long long int a,b,c,max,min; scanf("%lld%lld%lld",&a,&b,&c); max=a,min=a; if(b>c) { if(b>max) max=b; if(c<min) min=c; } else { ..原创 2021-10-30 23:01:23 · 293 阅读 · 0 评论 -
洛谷:P1424 小鱼的航程(改进版)
1、#include<iostream>#include<cstdio>using namespace std;int main(){ int x,x1,s1=0; long long int n,s2; scanf("%d%lld",&x,&n); s2=n/7*250*5; x1=n%7; for(int i=1;i<=x1;i++) { if(x>7) x-=7; if(x!=6&am..原创 2021-10-30 22:59:09 · 231 阅读 · 0 评论 -
洛谷:P1422 小玉家的电费
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int n; double s; scanf("%d",&n); if(n<=150) s=n*0.4463; else if(n<=400&&n>=151) s=150*0.4463+(n-150)*0.4663; else if(n>=401) s=150*0..原创 2021-10-30 22:56:51 · 218 阅读 · 0 评论 -
洛谷:P1055 [NOIP2008 普及组] ISBN 号码
1、#include<bits/stdc++.h>using namespace std;int main(){ int x=0; string s; cin>>s; for(int i=0;i<s.size();i++) { if(i==0) x=x+int(s[i]-48)*1; if(i==2) x=x+int(s[i]-48)*2; if(i==3) x=x+int(s[i]-48)*3; if(i==4) x=x+int(s[..原创 2021-10-30 22:53:19 · 250 阅读 · 0 评论 -
洛谷:P1909 [NOIP2016 普及组] 买铅笔
1、#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){ int i,j,k,n,m,w,ans; scanf("%d",&n); for(i=0;i<3;i++) { scanf("%d%d",&j,&k);m=j;w=k; wh..原创 2021-10-30 22:09:53 · 385 阅读 · 0 评论 -
洛谷:P1085 [NOIP2004 普及组] 不高兴的津津
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int t[8]; int a,b,j,max=0; for(int i=0;i<7;i++) { scanf("%d%d\n",&a,&b); if(a+b-8<=0) { t[i]=0; } else { t[i]=a+b-8; } if(..原创 2021-10-30 22:08:02 · 258 阅读 · 0 评论 -
洛谷:P5716 【深基3.例9】月份天数
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int n,y; scanf("%d%d",&n,&y); if((n%4==0&&n%100!=0)||n%400==0) { if(y==1||y==3||y==5||y==7||y==8||y==10||y==12) { printf("31"); } e...原创 2021-10-30 22:06:40 · 324 阅读 · 0 评论 -
洛谷:P5715 【深基3.例8】三位数排序
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int a[5]; int tmp; scanf("%d %d %d",&a[0],&a[1],&a[2]); for(int i=1;i>=0;i--) { for(int j=0;j<=i;j++) { if(a[j]&g..原创 2021-10-30 22:05:01 · 383 阅读 · 0 评论 -
洛谷:P5714 【深基3.例7】肥胖问题
1、#include <iostream>#include <cstdio>using namespace std;int main(){ double s,m,h; scanf("%lf%lf",&m,&h); s=m/(h*h); if(s<18.5) cout<<"Underweight"; else if(s>=18.5&&s<24) cout<<"Normal"..原创 2021-10-29 22:45:15 · 304 阅读 · 0 评论 -
洛谷:P5713 【深基3.例5】洛谷团队系统
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int n,y1,y2; scanf("%d",&n); y1=5*n; y2=3*n+11; if(y1<y2) printf("Local"); else printf("Luogu"); return 0; }原创 2021-10-29 22:43:24 · 469 阅读 · 0 评论 -
洛谷:P5712 【深基3.例4】Apples
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int n; scanf("%d",&n); if(n==0) printf("Today, I ate 0 apple."); else if(n==1) printf("Today, I ate 1 apple."); else printf("Today, I ate %d apples..原创 2021-10-28 23:51:34 · 462 阅读 · 0 评论 -
洛谷:P5711 【深基3.例3】闰年判断
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int n; scanf("%d",&n); if((n%4==0&&n%100!=0)||n%400==0) printf("1"); else printf("0"); return 0; }原创 2021-10-28 23:49:47 · 173 阅读 · 0 评论 -
洛谷:P5710 【深基3.例2】数的性质
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int n; scanf("%d",&n); if(n%2==0&&n>4&&n<=12) printf("1 1 0 0"); else if(n%2==0&&(n<=4||n>12)) printf("0 1 1 0");..原创 2021-10-28 23:47:01 · 254 阅读 · 0 评论 -
洛谷:P3954 [NOIP2017 普及组] 成绩
1、#include<iostream>using namespace std; int main() { int a,b,c; scanf("%d%d%d",&a,&b,&c); int sum=a*0.2+b*0.3+c*0.5; printf("%d",sum); return 0; }原创 2021-10-28 23:45:01 · 110 阅读 · 0 评论 -
洛谷:P5707 【深基2.例12】上学迟到
1、#include<iostream>#include<cmath>using namespace std;int main(){ int s,v; double time; int minute,second; scanf("%d%d",&s,&v); time=s*1.0/v+10; time=ceil(time); if(time<=480) { minute=(480-time)/60; second=(int..原创 2021-10-28 23:43:04 · 202 阅读 · 0 评论 -
洛谷:P2181 对角线
1、#include <iostream>#include <cstdio>using namespace std;int main(){ unsigned long long n,j; scanf("%lli",&n); j=n*(n-1)/2*(n-2)/3*(n-3)/4; printf("%lli\n",j); return 0;}原创 2021-10-28 23:40:45 · 103 阅读 · 0 评论 -
洛谷:P5709 【深基2.习6】Apples Prologue / 苹果和虫子
1、#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){ double a,b,c,s,tmp; scanf("%lf%lf%lf",&a,&b,&c); tmp=(a+b+c)/2; s=sqrt(tmp*(tmp-a)*(tmp-b)*(tmp-c)); int n=(s+0...原创 2021-10-28 23:38:30 · 339 阅读 · 0 评论 -
洛谷:P1421 小玉买文具
1、#include <iostream>#include <cstdio>#include <string>//万能库 <bits/stdc++.h>using namespace std;int main(){ int a,b,c; scanf("%d%d",&a,&b); c=(a*10+b)/19; printf("%d",c); return 0; }原创 2021-10-28 23:36:35 · 214 阅读 · 0 评论 -
洛谷:P5708 【深基2.习2】三角形面积
1、#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){ double a,b,c,s,tmp; scanf("%lf%lf%lf",&a,&b,&c); tmp=(a+b+c)/2; s=sqrt(tmp*(tmp-a)*(tmp-b)*(tmp-c)); int n=(s+0...原创 2021-10-28 23:31:53 · 260 阅读 · 0 评论 -
洛谷:P1425 小鱼的游泳时间
1、#include <iostream>#include <cstdio>using namespace std;int main(){ int a,b,c,d,x,p,q; scanf("%d%d%d%d",&a,&b,&c,&d); x=(c-a)*60+d-b; p=x/60; q=x-p*60; printf("%d %d",p,q); }原创 2021-10-27 22:18:46 · 85 阅读 · 0 评论 -
洛谷:P5706 【深基2.例8】再分肥宅水
1、#include <iostream>#include <cstdio>using namespace std;int main(){ double x; int a; scanf("%lf%d",&x,&a); printf("%.3lf\n",x/a); printf("%d",2*a); }原创 2021-10-27 22:16:32 · 307 阅读 · 0 评论 -
洛谷:P5705 【深基2.例7】数字反转
1、#include <iostream>#include <cstdio>#include <cmath>using namespace std;int main(){ char a,b,c,d; scanf("%c%c%c.%c",&a,&b,&c,&d); printf("%c.%c%c%c",d,c,b,a); return 0 ; }原创 2021-10-27 22:15:00 · 343 阅读 · 0 评论 -
洛谷:P5704 【深基2.例6】字母转换
1、#include<iostream> #include <stdio.h>#include <time.h>#include<math.h>using namespace std;int main(){ char a; scanf("%c",&a); printf("%c",a-32); return 0;}原创 2021-10-27 22:12:44 · 160 阅读 · 0 评论 -
洛谷:P5703 【深基2.例5】苹果采购
1、#include<iostream> #include <stdio.h>#include <time.h>#include<math.h>using namespace std;int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a*b); return 0;}原创 2021-10-27 22:11:18 · 208 阅读 · 0 评论 -
洛谷:P1001 A+B Problem
每次思考都是一次进步1、没什么好说的,直接输入a,b,输出a+b。毕竟是人生做的第一题,还是有点意义的。#include <iostream>using namespace std;int main(){ int a,b; cin >> a >> b; cout << a+b; return 0; } ...原创 2021-10-17 18:36:40 · 92 阅读 · 0 评论