码迷,mamicode.com
首页 > 其他好文 > 详细

UCF Local Programming Contest 2012(Practice)

时间:2020-04-01 10:35:44      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:scan   define   efi   ace   std   模拟   tin   tor   practice   


B和H是两个水题C题是个模拟题,按照题目意思模拟就可以,只不过需要注意输出格式(指数行和底数行不能同时出现数字),G题也是个模拟题,题意是给出一个字符串,问能不能由上面那两个替换公式经过有限次替换得到,类似模拟括号匹配中栈的操作,不同的是不能出现紧挨的‘ab‘(可以是‘ba‘)。


//
H #include <iostream> #include <algorithm> using namespace std; typedef long long ll; int main() { int n; cin >> n; int i=1; ll a[5]; for(int i=1;i<=n;i++) { for(int j=0;j<3;j++) { cin >> a[j]; } printf("Data set #%d:\n",i); printf(" Original order: %lld %lld %lld\n",a[0],a[1],a[2]); sort(a,a+3); printf(" Smallest to largest: %lld %lld %lld\n",a[0],a[1],a[2]); printf("\n"); } return 0; } //B #include <bits/stdc++.h> using namespace std; typedef long long ll; string s[3]; int main() { int t; cin >> t; string a,b; s[0]="First string is older"; s[1]="First string is younger"; s[2] = "The two strings are the same age"; cout << s[0]<<endl; for(int i=1;i<=t;i++) { cin >> a >> b; ll p[26]={0},q[26]={0}; for(int j=0;j<a.length();j++) { p[a[j]-a]++; } for(int j=0;j<b.length();j++) { q[b[j]-a]++; } int flag =0 ,bgm =0; for(int j=25;j>=0;j--) { if(p[j]>q[j]) { flag=1; break; } else if(p[j]<q[j]) { bgm =1; break; } } printf("Data set #%d: ",i); if(flag) { cout<<s[0]<<endl; } else if(bgm) { cout<<s[1]<<endl; } else{ cout<<s[2]<<endl; } printf("\n"); } } //c #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<pair<int,int>>v; const int N = 1e4 +10; struct node{ ll p,q; }; map<int,int>mp; node nd[N]; int kg1[N],kg2[N]; bool cmp(node x, node y) { return x.p<y.p; } int main() { int n; cin >> n; for(int i=1;i<=n;i++) { memset(kg2,0,sizeof(kg2)); memset(kg1,0,sizeof(kg1)); memset(nd,0,sizeof(nd)); mp.clear(); int m; cin >> m; int cun =1; for(int j=1;j<=m;j++) { int a,b; scanf("%d%d",&a,&b); if(mp[a]>0) { nd[mp[a]].q+=b; } else{ mp[a] = cun; nd[cun].p = a; nd[cun].q = b; cun++; } } sort(nd,nd+cun,cmp); printf("Prime Factorization #%d:\n",i); for(int j=1;j<cun;j++) { int xy =nd[j].q; int num =0; while(xy) { xy/=10; num++; } kg1[j]=num; //printf(" %lld",nd[j].q); } //printf("\n"); for(int j=1;j<cun;j++) { int xy =nd[j].p; int num =0; while(xy) { xy/=10; num++; } kg2[j]=num; //printf("%lld%c",nd[j].p,j+1==cun?‘\n‘:‘ ‘); } for(int j=1;j<cun;j++) { for(int k=1;k<=kg2[j];k++) { printf(" "); } printf("%lld",nd[j].q); } printf("\n"); for(int j=1;j<cun;j++) { printf("%lld",nd[j].p); for(int k=1;k<=kg1[j];k++) { printf(" "); } } printf("\n"); if(i!=n) printf("\n"); } return 0; }
//G
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); typedef long long ll; #define P 3.14159265358979 const int maxn=2e5+10; ll a[maxn],dp[maxn]; map<char,int>mp; int main(){ int t ; cin >> t; int sum=0; int tt=t; while(t--){ sum++; string s; cin >> s; cout << "Pattern "<< sum<<": "; stack<int> st; int vis[100]; memset(vis,0,sizeof(vis)); int len=s.length(); int aa[100],bb[100]; int cnta=0,cntb=0; int flag=0; for(int i=0;i<len;i++){ if(s[i]==a){ aa[++cnta]=i; continue; } if(s[i]==b){ bb[++cntb]=i; continue; } if(s[i]==c) continue; flag=1; } // cout << cnta << " " << cntb << endl; if(flag||(cnta!=cntb)) { cout<< "Still Looking." << endl; if(sum!=tt) cout << endl; continue; } int flag2=0; for(int i=0;i<len;i++){ if(s[i]==c) continue; if(s[i]==a) st.push(i); if(s[i]==b){ int flag3=0; int t=st.top(); for(int j=t+1;j<i;j++){ if(vis[j]==3) flag3=1; if(s[j]==c) flag3=1; } if(flag3==1){ for(int j=t;j<=i;j++){ vis[j]=3; } st.pop(); } else{ flag2=1; break; } } } if(flag2==1) cout<< "Still Looking." << endl; else cout << "More aliens!" << endl; if(sum!=tt) cout << endl; } return 0; }

 

UCF Local Programming Contest 2012(Practice)

标签:scan   define   efi   ace   std   模拟   tin   tor   practice   

原文地址:https://www.cnblogs.com/wsxmmfby-jy/p/12610734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!