round 3

A.

给定长、宽、高,计算体积

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    int a,b,c;cin>>a>>b>>c;
    cout<<a*b*c;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

B.

用pow()函数即可

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    int n;cin>>n;
    cout<<"2^"<<n<<" = "<<pow(2,n);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

C.

输出给定数和个字符串

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    string s="Wang!";
    int a,b;cin>>a>>b;
    a=a+b;
    for(int i=1;i<=a;i++)cout<<s;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

D.

直接计算输出

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    char c;cin>>c;
    double x;cin>>x;
    if(c=='F')cout<<fixed<<setprecision(2)<<x*1.09<<'\n';
    else if(c=='M')cout<<fixed<<setprecision(2)<<x/1.09<<'\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    cin>>left;
    while(left--){
        solve();
    }
}

E.

暴力判断每个数

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    int n;cin>>n;
    int last,f=0;
    for(int i=2;i<=9;i++){
        int tmp=n*i;
        int sum=0;
        while(tmp){
            sum+=tmp%10;
            tmp/=10;
        }
        if(i==2){
            last=sum;
            continue;
        }
        if(sum==last)continue;
        else{
            cout<<"NO\n";
            f=1;
            break;
        }
    }
    if(f==0)cout<<last<<'\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    cin>>left;
    while(left--){
        solve();
    }
}

F.

用字符串函数模拟

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    string s;
    int cnt_total=0,index=0,cnt=0,f=0;
    while(1){
        getline(cin,s);
        if(s==".")break;
        cnt_total++;
        if(s.find("chi1 huo3 guo1")==string::npos)continue;
        else{
            if(f==0){
                index=cnt_total;
                f=1;
            }
            cnt++;
        }
    }
    cout<<cnt_total<<'\n';
    if(cnt)
    cout<<index<<' '<<cnt;
    else cout<<"-_-#";
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

G.

字符串模拟

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

void solve() {
    int t;cin>>t;
    string s;
    getline(cin, s);
    while(t--) {
        getline(cin, s);
        s=" "+s;
        int index=s.find(",");
        int id=s.size()-1;
        if(s[index-3]=='o'&&s[index-2]=='n'&&s[index-1]=='g'
        &&s[id-3]=='o'&&s[id-2]=='n'&&s[id-1]=='g'){
            int cnt_blank=0;
            for(int i=id;i>=0;i--){
                if(s[i]==' '){
                    cnt_blank++;
                    if(cnt_blank==3){
                        s+="qiao ben zhong.";break;
                    }
                }
                s.pop_back();
            }
            string tmp=s.substr(1);
            cout<<tmp<<'\n';
        }else{
            cout<<"Skipped\n";
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

F.

结构体排序输出

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

struct node{
    string name;
    double price;
}g[15];
bool cmp(node x,node y){
    return x.price>y.price;
}
void solve() {
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        string s;getline(cin,s);
        getline(cin,g[i].name);
        cin>>g[i].price;
    }
    sort(g+1,g+1+n,cmp);
    cout<<fixed<<setprecision(2)<<g[1].price<<", "<<g[1].name<<'\n';
    cout<<fixed<<setprecision(2)<<g[n].price<<", "<<g[n].name<<'\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

L.

深度优先搜索

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

vector<int>v;
int g[1010][1010],vis[1005];
int n,m,s;
void dfs(int u){
    for(int i=1;i<=n;i++){
        if(g[u][i]&&vis[i]==0){
            vis[i]=1;
            v.push_back(i);
            dfs(i);
            v.push_back(u);
        }
    }
}
void solve() {
    cin>>n>>m>>s;
    for(int i=0,u,v;i<m;i++){
        cin>>u>>v;
        g[u][v]=g[v][u]=1;
    }
    v.push_back(s);
    vis[s]=1;
    dfs(s);
    int f=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            f=1;
            break;
        }
    }
    cout<<s;
    for(int i=1;i<v.size();i++){
        cout<<" "<<v[i];
    }
    if(f)cout<<" 0";
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

M.

最小生成树板子

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N=1e5+10;
#define inf 0x3f3f3f3f

int fa[1010];
struct node{
    int u,v,w;
}edge[3010];
bool cmp(node x,node y){
    return x.w<y.w;
}
int find(int x){
    if(fa[x]==x)return fa[x];
    fa[x]=find(fa[x]);
    return fa[x];
}
void solve() {
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=m;i++){
        cin>>edge[i].u>>edge[i].v>>edge[i].w;
    }
    sort(edge+1,edge+m,cmp);
    int cnt=0,f=0,ans=0;
    for(int i=1;i<=m;i++){
        int fa_u=find(edge[i].u),fa_v=find(edge[i].v);
        if(fa_u==fa_v)continue;
        cnt++;
        fa[fa_u]=fa[fa_v];
        ans+=edge[i].w;
        if(cnt==n-1){
            f=1;break;
        }
    }
    if(f)cout<<ans<<'\n';
    else cout<<"Impossible\n";
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int left=1;
    //cin>>left;
    while(left--){
        solve();
    }
}

posted @ 2024-02-16 18:43  WW爆米花  阅读(6)  评论(0编辑  收藏  举报