Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ///Avem un sir cu n nr naturale. Sortati nr din sir cresc dupa prima cifra:
- /*
- IN:
- 6
- 89 22 91 4005 51 721
- OUT:
- 22 4005 51 721 89 91
- */
- int main(){
- ifstream cin("test.in");
- ofstream cout("test.out");
- //Andreea -declaratii
- int n,a[501],i,x,y,sumx,sumy,c;
- //Georgiana -citire sir
- cin>>n;
- for (int i=1;i<=n;i++){
- cin >> a[i];
- }
- for(i=1; i<=n; i++){
- for(int j=i+1 ; j<=n ;j++){
- x=a[i];
- y=a[j];
- sumx=0;
- sumy=0;
- ///G
- while(x>=10){
- x=x/10;
- }
- while(y>=10){
- y=y/10;
- }
- if(x>y){
- swap(a[i],a[j]);
- }
- }
- }
- //Bianca -afisare sir
- for(i=1; i<=n; i++){
- cout<<a[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement