int main()
{
    unsigned long rev(unsigned long temp);
    unsigned long test;
    scanf("%lu",&test);
    while(test--)
    {
        unsigned long k=0,num;
        scanf("%lu",&num);
        while(num!=rev(num))
        {
            num=num+rev(num);
            k++;
        }
        printf("%lu %lu\n",k,num);
    }
    return 0;
}
Exemplo n.º 2
0
    void recoverRotatedSortedArray(vector<int> &nums) {
        // write your code here
        // first find rotation point.
        int i = 1, n = nums.size();
        if (n == 1) return;
        
        for (; i < n; ++ i) {
            if (nums[i] < nums[i-1]) {
                break; // i-1 is rotation position.
            }
        }
        
        if (i == n) { return; } // no rotation.

        rev(nums, 0, i - 1);
        rev(nums, i, n - 1);
        rev(nums, 0, n - 1);
    }
void reverseWords(char *s)
{
    char *start, *end;
    
    if (s == NULL || *s == '\0') return;
    trim(s);
    if (*s == '\0') return;
    start = end = s;
    while (*end != '\0') {
        if (*end == ' ') {
            rev(start, end-1);
            start = end + 1;
        }
        end++;
    }
    rev(start, end-1); /* reverse last word */
    rev(s, end-1); /* reverse whold string */
}
Exemplo n.º 4
0
struct node* rev(struct  node*s)
{   if(s==NULL)return NULL;
    else
    {   int temp=top(s);
        s->next=rev(s->next);
        s=insert(s,temp);
        return s;
    }
}
Exemplo n.º 5
0
Arquivo: main.cpp Projeto: Ilos/Pong
// w= 119 a= 97 s= 115 d= 100
int main() {
	int exit = 0;
	int kp = 0;




	do {
		kp = _kbhit();
		if ( kp == 1) keypress(&exit, &kp);
		if (kp == 119 && pl1.paddle > 1) pl1.paddle--;
		if (kp == 115 && pl1.paddle < 18) pl1.paddle++;

		if (ball.y < 1 || ball.y > 18) rev(&ball.dy);
		if (ball.x < 3 || ball.x > 58) rev(&ball.dx);
		if (ball.x < 3 && (pos(pl1.paddle - ball.y) > 2)) pl2.pts++;
		if (ball.dx == 1) ball.x++; else ball.x--;
		if (ball.dy == 1) ball.y++; else ball.y--;
		

		std::cout << "--------------------------------------------------------------" << std::endl;
		
		for (int i = 0; i < 20; i++) {

			std::cout << "|";

			for (int j = 0; j < 60; j++) {
				if ((pos(pl1.paddle-i) <= 1) && (j == 1) && (1 <= i <= 14)) std::cout << ">";
				else if ((ball.x == j) && (ball.y == i)) std::cout << "*";
				else std::cout << " ";
			}

			std::cout << "|" << std::endl;
		}

		std::cout << "--------------------------------------------------------------" << std::endl;
		std::cout << "           Player 1        " << pl1.pts << " : " << pl2.pts << "       Player 2            " << std::endl;
		
		Sleep(50);
		system("cls");
		kp = 0;
	} while (exit != 1);	
	return 0;
}
Exemplo n.º 6
0
int main()
{
	//freopen("data.txt","r",stdin);
//	freopen("data.in","w",stdout);
	char ch[100];
	while(gets(ch)!=NULL)
	{
		int i, j = 0;
	 	len = strlen(ch);
		for(i = 0;i < len;i ++)
		{
			if(ch[i] == ' ') continue;
			if(ch[i+1] != ' ' && ch[i+1]!='\0')
			{
		 		dic[j] = a[j] = (ch[i] - '0')*10+ch[i+1]-'0';
		 		i++;
			}
			else
				dic[j] = a[j] = ch[i] - '0';
			j++;
		}
		len = j;
		//for(int j = 0;j < len;j++) printf("%d ",a[j]);
		qsort(dic,len,sizeof(dic[0]), cmp);
		puts(ch);//输出原始数据 
		
		for(j = 0;j < len;j ++)
		{//printf("%d ",dic[j]);
			if(a[len-j-1] == dic[j]) continue;
			if(a[0] == dic[j])
			{
				rev(0,len-j-1);
				printf("%d ",j+1);
				continue;
			}
			int pla = fin_pla(dic[j]);
			printf("%d %d ", len-pla, j+1);
			rev(0,pla);
			rev(0,len-j-1);
		}
		printf("0\n");
	}
	return 0;
}
int main()
{
    int i,j,p,q,n,s=0,s1=0;
    scanf("%d\n",&n);
    int a[10000];
    i=0;
      while(i<n){
        scanf("%d %d\n",&p,&q);
        s=rev(p)+rev(q);
        s1=rev(s);
        a[i]=s1;
        i++;
      }

    for(j=0;j<n;j++)
    {
        printf("%d\n",a[j]);
    }
}
Exemplo n.º 8
0
void 
BrushExample::
handle_event(FURYEvent::handle ev)
{
  if(ev->type()==FURYEvent::Resize)
    {
      FURYResizeEvent::handle rev(ev.static_cast_handle<FURYResizeEvent>());
      resize(rev->new_size().x(), rev->new_size().y());
    }
}
Exemplo n.º 9
0
void rev(){
    auto char c;
     scanf("%c",&c);
     if(c == 't'){
          printf("%c",c);
          return;
          }
     rev();
     printf("%c",c);
     }
Exemplo n.º 10
0
int main()
{
int num,temp;
printf("write the number to be reversed\n");
scanf("%d",&num);
temp = rev(num);
printf("the reverse of the number is %d", temp);

return 0;
}
Exemplo n.º 11
0
Arquivo: p42.c Projeto: alvinrxg/spoj
int main()
{
	int n, i;
	int n1, n2;
	int sum;

	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d %d", &n1, &n2);

		n1 = rev(n1);
		n2 = rev(n2);
		sum = n1 + n2;
		sum = rev(sum);

		printf("%d\n", sum);
	}
	return 0;
}
Exemplo n.º 12
0
int main(void) {
	char A[] = "hello world"; 
	int n = sizeof(A)-1;
	printf("%s\n %d\n" , A, n);

	rev(A, n);

	printf("%s\n" , A);
	return 0;
}
Exemplo n.º 13
0
int rev(int num, int len)
{
    if (len == 1)
    {
        return num;
    }
    else
    {
        return (((num % 10) * pow(10, len - 1)) + rev(num / 10, --len));
    }
}
int main()
{
    struct node *r;
	input();
	r = rev();
	printf("\nReversed List : \n");
	show(r);
	printf("\nOriginal list :\n");
	show(head);
	return 0;
}
Exemplo n.º 15
0
void rev(char s[],int i,int len)
{
    int j, c;
    j = len - (i+1);
    if (i < j) {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
        rev(s,++i,len);
    }
}
Exemplo n.º 16
0
main()
 {
  int m,n,**a,i,j,z,num,palin=0;
  clrscr();
  printf("Enter the dimensions of the matrix\n");
  scanf("%d%d",&m,&n);

  a=(int **) malloc(sizeof(int) *m*n);
  for(i=0;i<m;i++)
   *(a+i)=(int *) malloc(sizeof(int) * n);

  printf("Enter the elements\n");
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      printf("a[%d][%d]= ",i,j);
      scanf("%d",(*(a+i)+j));
     }
   }

  printf("Entered elements\n");
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      printf("%5d",*(*(a+i)+j));
     }
    printf("\n");
   }

  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      num=*(*(a+i)+j);
      z=rev(*(a+i)+j);
      if(z==num)
       palin++;
      *(*(a+i)+j)=z;
     }
   }
  printf("After revesing the elements\n");
  for(i=0;i<m;i++)
   {
    for(j=0;j<n;j++)
     {
      printf("%5d",a[i][j]);
     }
    printf("\n");
   }
   printf("Number of palindromes=%d\n",palin);
  getch();
 }
Exemplo n.º 17
0
int main(){
    int n;
    while(scanf("%s",op1) != EOF){
        if(strcmp(op1,"0")==0){
            printf("%d\n",1);
            continue;
        }
        rev(op1);
        sub1();
        memcpy(op2,res,PREC);
        mult();
        memcpy(op2,res,PREC);
        set_op1(2);
        add();
        rev(res);
        printf("%s\n",res);

    }
    return 0;
}
struct lst *rev(struct lst *h)
{   struct lst *p=h;
    if(!(p->next))
    {   h=p;
        return ; }
    rev(p->next);
    struct lst *q=p->next;
    p->next=NULL;
    q->next=p;
    return h;
}
Exemplo n.º 19
0
int main(){
    int i,n;
    memset(op1,0, PREC);
    memset(op2,0, PREC);
    while(scanf("%d",&n) != EOF){
        catalan(n);
        rev(res);
        printf("%s\n",res);
    }
    return 0;
}
Exemplo n.º 20
0
void main()
{
	int l;
	char st[10];
	clrscr();
	printf("Enter the string:");
	scanf("%s",st);
	l=strlen(st);
	rev(st,l);
	getch();
}
void number_to_str(float number, char *str,int afterdecimal){
	int n = (int)number, f = (int)((number - n) * power10(afterdecimal)), i= 0;
	if (number < 0)
		str[i++] = '-';
	// changing -ves to +ves
	if (n < 0) n = -n;
	if (f < 0) f = -f;
	str[i++] = n % 10 + '0';
	while (n /= 10)
		str[i++] = n % 10 + '0';
	rev(str, number < 0 ? 1 : 0, i - 1);
	if (afterdecimal) {
		str[i++] = '.';
		str[i++] = f % 10 + '0';
		while (f /= 10)
			str[i++] = f % 10 + '0';
		rev(str, i - afterdecimal, i - 1);
	}
	str[i] = 0;
}
Exemplo n.º 22
0
int main(){
    int i,l,impossible;
    ll b1,b2,b10,b1e = 1,b2e = 1;
    while(scanf("%lld %lld %s",&b1,&b2,inp) != EOF){
        b10 = 0;
        impossible = 0;
        b1e = b2e = 1;
        l=rev(inp);
        memset(res,0,100);
        for(i=0;i<l;i++){
            char aux;
            if(inp[i] >= 'A') aux = (inp[i] - 'A' + 10);
            else aux = (inp[i] - '0');
            if(aux >= b1){
                impossible = 1;
                break;
            }
            b10 += aux*b1e;
            b1e*=b1;
        }
        if(impossible){
            rev(inp);
            printf("%s is an illegal base %lld number\n",inp,b1);
            continue;
        }
        i=0;
        if(b10 != 0){
            while(b10){
                res[i] = chars[b10%b2];
                b10/=b2;
                i++;
            }
        }
        else res[0] = '0';
        rev(res);
        rev(inp);
        printf("%s base %lld = %s base %lld\n",
                inp,b1,res,b2);
    }
    return 0;
}
Exemplo n.º 23
0
int main()
{
	char nombre[10] = {"Cadena"};
	int arr[4] = {3, 5, 178, 2};
	int i;
	//ordenar(arr);

	rever(nombre);
	rev(&i);
	printf("%s\n", nombre);
	return 0;
}
Exemplo n.º 24
0
    string getPalindrome(vector<int> &nums, bool odd, char oddChar) {
        string s;
        for (int i = 0; i < nums.size(); ++ i) {
            s += (char) nums[i];
        }

        string s2 = rev(s);
        if (odd) s += oddChar;
        s += s2;
        
        return s;
    }
Exemplo n.º 25
0
int main(int argc, char *argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Mesh revision tool.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::ogs_version +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::ogs_version);
    TCLAP::ValueArg<std::string> input_arg("i", "input-mesh-file","input mesh file",true,"","string");
    cmd.add( input_arg );
    TCLAP::ValueArg<std::string> output_arg("o", "output-mesh-file","output mesh file",true,"","string");
    cmd.add( output_arg );
    TCLAP::SwitchArg simplify_arg("s","simplify","simplify the mesh (removing duplicated nodes)");
    cmd.add( simplify_arg );
    TCLAP::ValueArg<double> eps_arg("e", "eps","Minimum distance for nodes not to be collapsed",
                                    false, std::numeric_limits<double>::epsilon(),"float");
    cmd.add( eps_arg );
    TCLAP::ValueArg<unsigned> minDim_arg("d", "min-ele-dim","Minimum dimension of elements to be inserted into new mesh",
                                    false, 1, "unsigned");
    cmd.add( minDim_arg );
    cmd.parse( argc, argv );

    // read a mesh file
    std::unique_ptr<MeshLib::Mesh> org_mesh(
        MeshLib::IO::readMeshFromFile(input_arg.getValue()));
    if (!org_mesh)
    {
        return EXIT_FAILURE;
    }
    INFO("Mesh read: %d nodes, %d elements.", org_mesh->getNumberOfNodes(), org_mesh->getNumberOfElements());

    // revise the mesh
    std::unique_ptr<MeshLib::Mesh> new_mesh;
    if (simplify_arg.getValue()) {
        INFO("Simplifying the mesh...");
        MeshLib::MeshRevision rev(const_cast<MeshLib::Mesh&>(*org_mesh));
        unsigned int minDim = (minDim_arg.isSet() ? minDim_arg.getValue() : org_mesh->getDimension());
        new_mesh.reset(
            rev.simplifyMesh("revised_mesh", eps_arg.getValue(), minDim));
    }

    // write into a file
    if (new_mesh) {
        INFO("Revised mesh: %d nodes, %d elements.", new_mesh->getNumberOfNodes(), new_mesh->getNumberOfElements());
        MeshLib::IO::writeMeshToFile(*new_mesh, output_arg.getValue());
    }

    return EXIT_SUCCESS;
}
Exemplo n.º 26
0
int main() {

    // store answer in array
    for(int i=1;i<MAX;i++) dp[i]=i;
    for(int i=1;i<MAX;i++) {
        if(dig(rev(i)) == dig(i) && rev(i)<MAX) dp[i] = min(dp[i], min(dp[i-1]+1, dp[rev(i)]+1));
        else  dp[i] = min(dp[i], dp[i-1]+1);
    }

    // read input
    int T;
    scanf("%d", &T);
    for(int t=1;t<=T;t++) {
        int num;
        scanf("%d", &num);

        printf("Case #%d: %d\n", t, dp[num]);
    }

    return 0;
}
Exemplo n.º 27
0
void CMergeWizardRevRange::OnBnClickedBrowse()
{
    SVNRev rev(SVNRev::REV_HEAD);
    CAppUtils::BrowseRepository(m_URLCombo, this, rev);
    if (!rev.IsHead() && rev.IsNumber())
    {
        CString sUrl;
        m_URLCombo.GetWindowText(sUrl);

        m_URLCombo.SetWindowText(CPathUtils::PathUnescape(sUrl + L"@" + rev.ToString()));
    }
}
Exemplo n.º 28
0
int main(){
  scanf("%d",&T);
  while(T--){
    scanf("%lld%lld%lld%d",&e,&p,&q,&n);
    e=rev(e,(p-1)*(q-1));
    P=p*q;
    for(i=1;i<=n;i++){
      scanf("%lld",&x);
      printf("%lld%c",po(x,e),i<n?' ':'\n');
    }
  }
}
Exemplo n.º 29
0
void rev(char s[],int i)
{
	int c,j;
	j=(strlen(s)-(i+1));
	if(i<j){
		c = s[i];
		s[i] = s[j];
		s[j] = c;
		++i;
		rev(s,i);
	}
}
Exemplo n.º 30
0
main()
{
    int i,n;
    while(scanf("%d",&n) && n)
    {
        scanf("%s",s);
        for(i=0;s[i];i++);
        n=i/n;
        for(i=0;s[i];i+=n)rev(i,n);
        puts(s);
    }
}