結果

問題 No.185 和風
ユーザー dai11dai11
提出日時 2017-08-06 22:37:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 596 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 22,400 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 04:04:19
合計ジャッジ時間 556 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |   scanf("%d",&N); //N  個の正整数
      |   ~~~~~^~~~~~~~~
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%d %d",&X,&Y); //2 つ組(X,Y)
      |     ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>

int main()
{
  int i = 0; //カウンタ用
  int a = 0; //値の保管用
  int N; // N個の整数
  int X; // Xの値
  int Y; // Yの値

  scanf("%d",&N); //N  個の正整数

  for(i=0;i<N;i++)
  {
    scanf("%d %d",&X,&Y); //2 つ組(X,Y)
    
	//□ +Xk=Ykを求める式
	Y-=X;
    
	//存在しない条件
	if(Y <= 0)
     {
       printf("-1");
       return 0;
     }
    
    if(a == 0)
     {
       a = Y;
     }
    
	//正整数じゃない条件
    else if(a!=Y)
     {
       printf("-1");
       return 0;
     }
  }
  
  printf("%d",a);
  
  return 0;
}
0