#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int arr[30]; int main() { char str[1010]; char ch; int t; scanf("%d",&t); while(t–) { scanf("%s",str); for(int i=0;i<strlen(str);i++) { if(arr[str[i]-'a']==0) arr[str[i]-'a']=1; else arr[0]+=1; } for(int i=0;i<=25;i++) { if(arr[i]!=0) { ch = 'a'+i; for(int j=1;j<=arr[i];j++) printf("%c",ch); arr[i]=0; } } printf("\n"); } return 0; }
Month: March 2016
NCPC-3
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #define ul unsigned long long using namespace std; vector<int> vb; int gcd(int a,int b) { if(a%b==0) return b; else return gcd(b,a%b); } int main() { int kase=1; int t,increment,lim; ul n,sum=0; cin>>t; while(t–) { cin>>n; vb.clear(); lim = sqrt(n); if(n%2) increment = 2; else increment = 1;
NCPC-2
#include <iostream> #include <cstdio> using namespace std; int arr[10005]; int n; int Search(int num) { int i=1; while(i<=n) { if(arr[i]==num) return i; i++; } } /* 5 5 5 1 3 2 4 9 4 5 1 2 6 3 8 9 7 //Case 1/2: 3/6 */ int main() { int t,nxtIdx,kase=1; cin>>t; while(t–) {
NCPC-1
#include <iostream> #include <cstdio> #define ul unsigned long long using namespace std; ul twosPower[60]; ul binSearch(int Left) { int lw=0,hi=55; int mid; while(hi-lw>0) { mid = (lw+hi)/2; if(Left<twosPower[mid]) { hi=mid; } else if(Left>=twosPower[mid]) { lw=mid+1; } } return twosPower[lw-1]; } int recursion(ul Left,ul Right) { //<<"inside recur "<<Left<<" "<<Right<<endl; ul LeftNumberFloor; if(Left==0) return 0; else
11827
#include <iostream> #include <sstream> #include <cstdio> #include <cstring> #include <vector> using namespace std; vector<int> vb; int gcd(int a,int b) { if(a%b==0) return b; else return gcd(b,a%b); } int main() { int n,a; int x,y; string str; cin>>n; getchar(); stringstream iss; int mx; while(n–) { //cin>>x>>y; //cout<<gcd(x,y)<<"\n"; getline(cin,str); iss<<str; mx=0; vb.clear(); while(iss>>a) { //cout<<"sdd\n"; vb.push_back(a); }
10986
Single source shortest path algorithm and priority_queue used to solve the problem. #include <iostream> #include <queue> #include <cstdio> #include <vector> #define INF 1000000000 #define ll long long using namespace std; /* struct node{ int dest,weight; }; */ int n,m,src,dst; vector<pair<int,int> > vb[20005]; void dijkstra(vector<ll> distance) { int t_dist,t_node; int latency,v; pair<int,int> _intPair; priority_queue<pair<int,int>,vector<pair<int,int> >, greater<pair<int,int>
10223
#include <iostream> #include <cstdio> #define ll long long using namespace std; ll catalan[25]; ll findcatalan(int n) { ll res = 1; int lim; for(int i=n+2;i<=2*n;i++) { if(i%2==0) res*=2; else res*=i; } if((n+2)%2==0) lim = (n+2)/2; else lim = (n+3)/2; for(int i=2;i<lim;i++) { res/=i; } return res; } int binSearch(ll num) { int lw=0,hi=17; int mid;
11608
#include <iostream> #include <cstdio> //#include <fstream> using namespace std; //ofstream out; int main() { int kase=1; int arr[15]; int init_problem_num; int total_problem[15]; int problem_required[15]; //out.open("out.txt"); while(scanf("%d",&init_problem_num)) { if(init_problem_num<0) break; total_problem[0]=init_problem_num; for(int i=0;i<12;i++) { scanf("%d",&arr[i]); if(i>0) total_problem[i]=total_problem[i-1]+arr[i-1]; } for(int i=0;i<12;i++) scanf("%d",&problem_required[i]); printf("Case %d:\n",kase); //out<<"Case "<<kase<<":\n"; kase+=1; int problem_used=0; for(int i=0;i<12;i++) { if(problem_required[i]<=(total_problem[i]-problem_used)) { printf("No problem! :D\n");
11650
#include <cstdio> #include <iostream> #include <cstring> #include <string> using namespace std; void printTime(int tyme) { if(tyme<10) { printf("0%d\n",tyme); } else { printf("%d\n",tyme); } } int main() { int t,hour,min; scanf("%d",&t); char s[10]; int highest = 12*60; int lowest = 0; int mirror; while(t–) { scanf("%s",s); hour = (s[0]-'0')*10; hour += (s[1]-'0'); hour%=12; min = (s[3]-'0')*10;
11689
#include <iostream> #include <cstdio> using namespace std; int main() { int t; int e,f,c; int total_consumed,total_empty; scanf("%d",&t); while(t–) { scanf("%d%d%d",&e,&f,&c); total_consumed=0; total_empty=e+f; while(total_empty>=c) { total_consumed += (total_empty/c); total_empty = total_empty/c + total_empty%c; } cout<<total_consumed<<"\n"; } return 0; }