Advertisement
artur99

Untitled

Mar 19th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. using namespace std;
  5. int cate(int x) {
  6.     int c = 0;
  7.     while (x && ++c)x/=10;
  8.     return c;
  9. }
  10.  
  11. int UltimeleCifre(int x, int n) {
  12.     return x%(int)(pow(10, n)+0.1);
  13. }
  14.  
  15. int main() {
  16.     fstream citire("bac.txt", ios::in);
  17.     int anterior = -1;
  18.  
  19.     for(int x,y,citire>>x,int lx=cate(x);citire>>y;x == UltimeleCifre(y, lx)? anterior = y : 1){}
  20.  
  21.     anterior+1?cout<<anterior<<endl:cout<<"Nu exista."<<endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement