The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
Prvi manji
Posted by: Evgenije | February 5, 2010 @ 5:22am
C++ Code
[
Download
]
#include <iostream> #include <algorithm> #include <string> using namespace std; bool cmp( int a, int b ) { return a > b; } int main() { string broj; cin>>broj; int i=broj.length()-1; char prethodni=broj[i]; i--; char sljedeci=broj[i]; while (prethodni>sljedeci){ prethodni=sljedeci; i--; sljedeci=broj[i]; } char karakteristika=sljedeci; for (int j=broj.length()-1;j>i;j--){ if (broj[j]<karakteristika){ broj[i]=broj[j]; broj[j]=karakteristika; sort(broj.begin()+i+1,broj.end(),cmp); cout<< broj; return 0;} } cout<<"Nema takvog"; return 1; }
Syntax Highlighting
[
Open in new window
]
Author Comments
Zadatak: traži se prvi manji prirodan broj od prirodnog broja unesenog na ulazu takav da se sastoji od istih cifara (napomena: nije neophodno da se radi o dekadnom sistemu).
Rating
4.60 / 8
58 Votes